Python Get Started
Python code can run from a saved file or line by line in the REPL.
Run a saved file
Write these lines in an editor and save them as start.py. Run the file to see both lines.
print("First line from a file.")
print("Second line from a file.")Try the REPL
In the REPL, you type one line and see its result. The >>> sign means Python is waiting for you.
>>> print("Hello from the REPL")
Hello from the REPLThe interpreter works line by line
Python runs the first line first. Then it runs the next line.
print("Step one")
print("Step two")
print("Step three")Leave the REPL
Type exit() when you want to stop. Then press Enter.
>>> exit()Example
print("Learning Python step by step.")
print("One line at a time.")Key points
- File: a saved document that holds your code
- Use a .py file to save a program and run it again later
- REPL: the interactive mode where you type one line and see the result
- Use the python3 command with no file name to open the REPL
- Editor: a program for writing and saving code files
- Interpreter: the program that reads and runs your code line by line
- Python code runs in two ways, from a saved file or line by line in the REPL.
In this example, the first line prints a learning message. The second line prints a short follow-up line. You can save these lines in a file and run the file. You can also type them in the REPL for the same result.
Note
The REPL is great for quick tests.
Save real programs in a file so you can run them again.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Python Playground
Exercise
How do you leave the REPL?