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.

1. What does it mean to be an "interpreted" language?
2. What are the major steps involved with running a Python program on your local computer?
3. How do you run a Python source file from the command line?
4. What command-line addition do you need to make if the Python source file is located somewhere else on your computer?
5. What is an IDE and why might you want to use one as a developer?
6. How do you use the built-in Python interpreter within the course lessons?

1. Being an "interpreted" language means that the source code is read by an interpreter program and translated to machine commands "on the fly" or as the program is running. The interpreter translates each Python statement to one or more computer commands, and the program runs within the interpreter.

2. The major steps involved in running a Python program on your local computer are:
- 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.

3. To run a Python source file from the command line, you would type "python" followed by the name of your source file, including the ".py" file extension. For example, if your source file is named "hello.py", you would type "python hello.py".

4. If the Python source file is located somewhere else on your computer, you would need to include the full or relative path to the file after "python". For example, if your source file is located in the directory "Documents/My Projects" and it is named "hello.py", you would type "python Documents/My Projects/hello.py".

5. An IDE (Integrated Development Environment) is a software application that allows developers to create and run code in one graphical interface. It provides tools and features to simplify the development process, such as code editors, debugging tools, project management, and more. Using an IDE can make the coding and running process more efficient and streamlined.

6. In the course lessons, the built-in Python interpreter is provided in the form of an online Python engine. You can type your Python source code into the designated window, click the "Run Code" button, and see the results in the output panel. You don't need to install any software or work with a command-line interface in this case.