Python 2.0
Python 2.0
The official Python tutorial. This tutorial is designed to help people teach themselves Python.
While it goes in a different order than the one we're taking here, it covers a lot of the same
subjects that we explore in this course. You can refer to this resource for extra information on
these subjects.
The Think Python book. This book aims to teach people how to program in Python. It's available
online in PDF and browsable forms. Again, you can use this resource to learn more about some
of the subjects we cover.
The official language reference. This is a technical reference of all Python language components.
At first, this resource might be a little too complex, but as you learn how Python works and how
it’s built, this can be a useful reference to understand the details of these interactions.
In the meantime, you can still practice by using one of the many online Python interpreters or
codepads available online. There’s not much difference between an interpreter and a codepad.
An interpreter is more interactive than a codepad, but they both let you execute code and see the
results.
Below, you’ll find links to some of the most popular online interpreters and codepads. Give them
a go to find your favorite.
https://www.python.org/shell/
https://www.onlinegdb.com/online_python_interpreter
https://repl.it/languages/python3
https://www.tutorialspoint.com/execute_python3_online.php
https://rextester.com/l/python3_online_compiler
https://trinket.io/python3
While this course will give you information about how Python works and how to write scripts in
Python, you’ll likely want to find out more about specific parts of the language. Here are some
great ways to help you find additional info:
Welcome to Python
Keywords
A keyword is a reserved word in a programming language that performs a specific purpose. In
your first Python example, you briefly encountered the keywords for and in. Note that keywords
will often appear in bold in this course.
In the next few weeks, you will also learn the following keywords:
Values: True, False, None Conditions: if, elif, else Logical operators: and, or, not Loops: for,
in, while, break, continue Functions: def, return
You don't need to learn this whole list now. We'll dive into each keyword as we encounter them.
There are additional reserved keywords in Python. If you would like to read about them, please
visit the linked “Python Keywords” article in the Resources section at the end of this study
guide.
Arithmetic operators
Python can calculate numbers using common mathematical operators, along with some special
operators, too:
1. Parentheses ( ), { }, [ ]
2. Exponents xe (x**e)
You might find the PEMDAS mnemonic device to be helpful in remembering the order.
Python Keywords - Lists Python’s reserved keywords and a brief description of what each
keyword does.
Different Arithmetic operators in Python - Provides more examples of the proper syntax for
using arithmetic operators in Python.
For additional Python practice, the following links will take you to several popular online
interpreters and codepads:
Welcome to Python
To check which version of Python you have installed on your Mac, use the following command.
python --version
python3 --version
To check for Python, use the following command. The version of Python you installed will appear.
python --version
You can begin writing Python code from the terminal. Simply type python to use the interactive
mode. You can also write Python scripts using Linux with IDLE which we will cover next.
Using IDLE
Python IDLE is included with Python installations on Windows and MacOS. You can download IDLE
using your package manager on Linux. Python IDLE is an interactive interpreter or file editor that
allows you to easily write Python scripts and programs. IDLE provides syntax highlighting, code
completion, and automatic indentation.
Double click on the IDLE icon to open it on your computer. This will open a blank Python interpreter
window. You can begin writing code right away.
You can also open a new file. Go to File → Open → New File from the menu bar. Here you can write
a Python file. Once you have completed writing your Python code in the file, go to File → Save As.
Give your Python file a name. Hit Save. To run the Python code in the file you saved click Run →
Run Module from the menu.
Sum.py File
Sum.py Output
Key takeaways
Whichever operating system you are using, you will be able to run Python from the command-line.
Using a text editor like IDLE and running python from the command-line is best for executing and
debugging individual scripts or .py files.
A guide to using terminal (command-line) on Mac, Windows, and Linux operating systems.
Use VS Code
VS code is an open source code editor that includes developer tooling. It is similar to Jupyter
Notebooks and Colab, but it includes more features. VS code provides built-in support with
Intellisense code completion, an interactive debugger, and other build and scripting tools. VS code
has a simple design that is easy to use. Its intuitive features make it a great choice for coding in
Python!
python3 --version
py -3 –version
$python3 -- version
Python 3.11.3
$python3 -- version
command not found: python
Next, you will install the Python extension. You can do this by visiting the VS Code Marketplace.
Follow the download instructions there. You can check to make sure the Python extension was
added successfully by clicking on this icon in VS Code.
Note: You cannot use VS Code Marketplace to install the Python extension on MacOS.
For MacOS, open the command palette in VS code. You can do this by hitting Cmd+Shift+P. Type
‘shell command’. Find the Shell Command: Install ‘code’ command in PATH.
Once this is completed you can begin writing, running, and debugging Python code in VS Code!
print(“Hello World!”)
Next, click on the Run and Debug icon in the left hand toolbar.
You will be prompted to name and save your file. Give your Python file a name and click save.
Your code will run and you will see its output here.
Now you know the basics of VS Code and how to use it!
Key takeaways
VS Code is an extremely robust source code editor. It uses Intellisense technology which provides
syntax highlighting and autocomplete for coding. VS code allows you to debug right in the editor with
its interactive console. Overall, VS code is extremely interactive and customizable. There is also a
large library of extensions that are easily integrated!
This resource provides more information on using Python with VS Code and also includes a tutorial
you can follow along with.
PyCharm
PyCharm is a very popular IDE for Python development. It is an open source IDE that offers many
great features to help you write better code faster. It is an intelligent code editor that has useful
features, including code completion, error detection, and on-the-fly code fixes. PyCharm also allows
you to navigate easily through your code with code folding, code search, and code structure
diagrams. The built-in debugger provides breakpoints, step-by-step execution, and variable
inspection which allows you to find and fix bugs very quickly. You can test your code within the IDE
which allows you to ensure your code is reliable and error free. Finally, PyCharm also offers a wide
range of plug-ins created by its community of developers which has expanded its functionality.
Overall, PyCharm is a great choice when it comes to an IDE. It is great for beginners because it is
easy to use and has a large community of users which means there are tons of tutorials and
resources available online. PyCharm is also highly customizable. It is a popular IDE that many
developers use and love!
PyDev
PyDev is an open source IDE for Python Development that is based on Eclipse. PyDev includes an
intelligent code editor, code navigation, debugging, testing, and refactoring. Its refactoring engine
can help you improve the structure and readability of your code which makes maintenance and
debugging easier. PyDev is also fully integrated with Eclipse which means you can use all of
Eclipse’s features like project explorer, the perspective system, and its built-in debugger.
PyDev is a great IDE for developers at any stage! It's free to use, compatible with many versions of
Python, and its plugins make it extensible. PyDev has a large community of users and developers
which means there are lots of tutorials, resources, and forums online.
Atom
Atom is an open source text editor developed by GitHub. It is a highly customizable editor with
thousands of plugins available. Atom includes syntax highlighting, code completion, and debugging.
Atom is lightweight, very easy to install, and can be used on any operating system.
Atom is a popular choice for Python developers. It is free to use, has a large community of users,
and has an intuitive interface!
Key Takeaways
PyCharm, PyDev, and Atom are popular tools used for writing Python code. To try them out, you can
download and install them here!
Here are some resources you might find useful as you dive deeper into Python programming.
This blog includes the latest news and updates on Jupyter Lab and Jupyter Notebooks.
This resource includes tons of tips and tricks for using VS Code.
This reading includes more information on some of the features Colab has to offer, including GitHub
integration, keyboard shortcuts, and more!
This resource has tons of information on IDLE. It covers everything from working with files to
debugging and more!