Python can be tricky to run at first on some computers. Always ask if you're having trouble.

On Mac OS X: (including in-lab computers)

You'll be running python from the Terminal application that we learned about on the last page.

On Windows

Python may not be set up properly on Windows. If you are unable to get python to work from the command line (as explained below) here is a link that will help you get things set up if you'd like to continue working on your Windows machine. Please download the latest version of Python. As of October 17, 2023, the latest version of Python is 3.12.0.

Running Python

The first step is to open the Python interpreter. On the command line in your terminal, use the command python3. If you see something like "command not found", then use the command python instead. You should see something similar to the following:


Alonzos-MacBook:~ alonzo$ python3
Python 3.12.0 (v3.12.0:04f714765c13, Month DD YYYY, HH:MM:SS)
[GCC X.X.X] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
        


python and python3, what's the difference? When you open Python with one of these commands, check out the text that appears like above. You'll see something like Python 3.12.0 or Python 3.9.1. These are just different versions of Python. The folks who develop Python release updates as new versions, just like apps on the App Store. Don't worry, both versions will work for this lab.


We're now using Python! Notice that we still have a prompt, but it looks like this now: >>>. The >>> indicates that we're using Python right now, and is where we can type Python code. After typing a line of code, hitting enter will tell the python interpreter to run the instruction. Try typing the following into the interpreter:


>>> 3 + 5
8
        

If the text cursor is on a line beginning with >>>, the command line window has an active python interpreter open. That means we can't do commands like cd, or ls, because the program is expecting Python code. To leave the python interpreter, type the exit command exit() and press enter.


>>> exit()
Alonzos-MacBook:~ alonzo$
        

Any functions or variables created in the python interpreter are erased when the exit() command is run.

Here are some basic concepts about the Python intepreter you should understand before you move on: