Python is a programming language. It interprets instructions that you, the programmer, give it, and it executes them. Think of it like a robot you can give a series of commands to ahead of time, and then have it run off and do them on its own.
In programmer parlance, we call these sets of instructions code.
In addition to being a programming language, Python is also a program, itself! It’s a program that runs other programs! We don’t have to worry about the details of that at all, except that since Python is a program, it’s something we’ll have to install on our computers.
Python comes in different versions. The big versions are 2 and 3. We’ll be using Python 3 for everything in this book. Python 2 is older, and is rarely used in new projects.
Python also comes with an Integrated Development Environment, or IDE. An IDE is a program that helps you write, run, and debug (remove the errors from) code.
It’s main components are:
The editor. This is like a word processor except specifically designed for use with code.
The debugger. This helps you step through your code a line at a time and watch the data values change as you go. It can help you find places where your code is incorrect.
The console or terminal. This is a window where the output from your program appears (and where you might type input to the program).
The name of Python’s built-in IDE is IDLE. There are other IDEs we’ll talk about later.
There are two ways to do this:
I can’t see any disadvantage to installing it from the store. Just remember to install Python 3 (not Python 2).
If you install it from the official website4, you need to remember to check the “Add to PATH” box during the install procedure!
Another option to installing Python on Windows is through WSL. We’ll cover this later.
Download and install Python for Mac from the official website5.
Another option to installing Python on Mac is through Homebrew. We’ll cover this later.
The Linux community tends to be pretty supportive of people looking to install things. Google for something like ubuntu install python3
, replacing ubuntu
with the name of your distribution.
Here’s where we get to run the IDE for the first time. First we’ll look at how to do it on various platforms, and then we’ll run some Python code in it.
Running IDLE depends on the platform:
Platform | Commands |
---|---|
Windows | Hit the Start menu and type “idle”. It should show up in the pick list and you can click to open it. |
Mac | Hit CMD-SPACE and type “idle”. It should show up in the pick list and you can click to open it. |
Unix-like | Type idle in the terminal or find it in your desktop pulldown menu. |
If you run idle
on the command line and it says something about the command not being found, try running idle3
.
If you get an error on the command line that looks like this:
** IDLE can't import Tkinter. Your Python may not be configured for Tk. **
you’ll have to install the Tk graphical toolkit. This might be a package called tk
or maybe python-tk
. If you’re on a Unix-like, search for how to install on your system. On a Mac with Homebrew, you can brew install python-tk
.
If you get another error, cut and paste that error into your favorite search engine to see what other people say about how to solve it.
Once IDLE is up, you should see a window that looks vaguely like this:
In the IDLE window after the >>>
prompt, type:
print("Hello, world!")
and hit RETURN
. This commands Python to output the words “Hello, world!”.
>>> print("Hello, world!")
! Hello, world
And it did!
This is just the beginning!