Computer programs written in Python start as source files or source code. These files, normally ending with a ".py" extension, contain the human-readable Python code that makes up a program. In this lesson, we will discuss how Python source code can be executed or run to see the program results.

Interpreted Languages
Python is an example of an interpreted language. This means the source files are read by a Python interpreter program and converted to machine commands "on the fly" or as the program is running. Therefore, to run a Python program, you must have a Python interpreter to translate the source code into a working program.

Interpreter translates source code to Python program

The Python interpreter will read the source code and translate each Python statement to one or more meaningful computer commands. The resulting collection of computer commands is your fully functional Python program, which actually runs within the interpreter.

Running Python on Your Computer
You can, of course, create Python code and run Python programs directly on your computer. A Python interpreter program is available for Windows, Mac OS, Linux, and other operating systems. If you want to run Python on your computer, then you would follow these steps:

Ensure you have a Python interpreter installed on your computer
Create the Python ".py" source code files
Run the Python interpreter with the source files to produce the program output
For example, here is a one-line Python source file named "alive.py" that will print a message to the screen.

print("I'm Alive!")
Copy
Once you have installed your Python interpreter and created a Python source file, you can run the program from the Windows Command Prompt or Mac OS Terminal. To run the source code in your Python interpreter, from the command prompt or terminal you would type "python" and then the name of your source file, including the ".py" file extension.

/users/student> python alive.py
I'm Alive!
In many cases, your Python source code will be stored in some other directory on your computer. In that case, you would include the full or relative path to the file after "python", as demonstrated below.

/users/student> python "Documents/My Projects/alive.py"
I'm Alive!
In this example, the Command Prompt started in the "/users/student" directory, and we saved the "alive.py" source file in "/users/student/Documents/My Projects" directory. So, we passed the path "Documents/My Projects/alive.py" to help Python find the right source file.

Over time, software engineers have developed many useful tools to help them write code and run programs. An Integrated Development Environment or IDE is a software application that lets programmers create and run code in one graphical interface. When using an IDE, you don't have to use separate text editors to create source code or open a command line to run the program. Python comes with an easy-to-use IDE (shown below) if you choose to write Python code on your own computer.

Python IDE Example

Instructions for installing Python on your computer, creating Python source files, and running a Python program can be found in the first Supplemental chapter near the end of the course. However, running Python on your computer is not required in most cases! Instead, you can use our online Python engine as described below.
Running Python in Our Online Course
To run Python successfully on your local computer, you need to install the Python interpreter, create and save source files, successfully open a Command Prompt, or Terminal and understand the exact path to your Python source file. These steps can be somewhat complex for a new programmer, especially if you have never used a command-line interface before.

Fortunately, there is an easier option! We have created a special online Python interpreter that you can use directly from your course lesson pages! You don't need to install any software, create and save text files or work with a command-line interface. Simply type your Python source code into one window, click a button, and see the results in the output panel.

Give our online Python interpreter a try below! Click the "Run Code" button to see the results in the Console panel. Some exercises will have hints or solutions that you can see by clicking those buttons as well.

Try It Now
alive.py



You can change the "I'm Alive!" text to something else and click "Run Code" again to see the new output. Just be sure to leave the rest of the source code alone. We'll explain how the print() statement works in the next lesson.

If you need to start over from the default code on any of these in-lesson Python panels, simply reload your web page in your browser. Press "CTRL+F5" on Windows or "Command+R" on Mac OS to force your lesson page to reload.

Straight Quotes and iPad / iOS Devices
Python (and other programming languages) use single (') or double (") quotes to mark the beginning and ending of pieces of text like "Greetings". These quote marks must be typed in as "straight" quote marks. Fancy, curly or slanted quote marks (like “ or ”) will not work in Python code!

If you are using an iPad or iOS device to type code in our online Python boxes or a local text editor, your device may automatically convert straight quotes to curly or "smart" quotes. You must disable the "Smart Punctuation" feature on your iOS device to successfully write Python code!

To disable Smart Punctuation on your iOS device, follow these steps:

Go to "Settings > General > Keyboard"
Turn off the "Smart Punctuation" toggle
When you are done, verify that single and double quotes you type into our code panels remain "straight".

iPad and iOS users must follow the steps above to disable Smart Punctuation. Windows users do not need to worry about this process, as your quotes are "straight" by default.

Python source code files typically have a ".py" extension and contain the human-readable code that makes up a program. To run a Python program, you need a Python interpreter to translate the source code into machine commands.

To run Python on your computer:
1. Install a Python interpreter.
2. Create Python ".py" source code files.
3. Open a command prompt or terminal and navigate to the directory where your source code files are located.
4. Run the Python interpreter with the source file as an argument: `python your_file.py`.

You can also use an Integrated Development Environment (IDE), which allows you to write and run code in one graphical interface. Python comes with an easy-to-use IDE.

Alternatively, you can use an online Python interpreter, like the one provided in the course. This allows you to run Python code directly from the lesson pages without the need for installation or command-line interfaces.

It's important to use straight quotes (') or double quotes (") in Python code, as fancy or curly quotes will not work. If using an iPad or iOS device, you need to disable the "Smart Punctuation" feature to ensure straight quotes are used.

Overall, running Python on your computer is not necessary for most cases, as you can use the online Python interpreter provided in the course.