2016 September 12,

CS 111: Running Python Interactively

The Python programming language can be used in two different ways. First, Python can be used to run pre-written batches of commands, called programs. We'll learn about that later. Second, Python can be used interactively, like some sort of super-powered calculator. That's what we describe here.

Along the bottom of your screen is a row of icons, called the Dock. Each icon represents a program, folder, or document, that you can open by clicking. Locate and click the Terminal icon, to launch that program. (If it's not there, then ask for help.) You should see a window much like the following, although the color and text may be different.

Put simply, a terminal is a program that lets you run other programs — especially programs with textual interfaces. Right now the terminal is running the program bash. The > is a prompt indicating that bash is waiting for your command; your setup may use $ for a prompt instead of >, but that is just a cosmetic difference.

Type python3 and press the Return key. You have just told bash to run version 3 of the Python interpreter, which takes over the terminal. The bash program is still running; it's just temporarily hidden by the Python interpreter.

The prompt >>> indicates that the Python interpreter is waiting for your command. You can type exit() to exit the Python interpreter; then you find yourself back in bash. You can quit the Terminal program entirely by pressing Command-Q, if you like.