Getting started with Python
Run your first Python script
Create hello.py, run it from a terminal, and distinguish a saved script from the interactive prompt.
Lesson 3 of 63
Reading: about 2 min
Lesson + practice: about 10 min
Difficulty: Beginner
On this page4 sections
Create a plain-text file named hello.py inside your python-roadmap folder. Add this line and save the file.
print("Hello, Python!")Hello, Python!
Run the file
Open a terminal in the folder containing hello.py. Run the command below with the Python 3 command that worked in the setup lesson.
python hello.py
If you used py or python3 in the setup lesson, replace python in that command with the command that worked for you. The expected output is:
Hello, Python!
If Python cannot find hello.py, check that the terminal is in the correct folder and that the file was saved with the .py extension.
Interactive prompt versus script
Running your working Python command without a filename opens an interactive prompt where you can enter one instruction at a time. A .py file saves your instructions so you can edit and run them again. To leave the prompt, type exit().
Try it: run your working Python command without hello.py, type the line below at the >>> prompt, press Enter, and then type exit(). This does not change your saved hello.py file.
print("From the prompt")From the prompt
Why this works
The interactive prompt runs one entry as you type it. A script keeps several statements together and runs them from the file. Running python hello.py tells the interpreter which saved file to use; the message printed by the program is output, not another command to type.
Why save instructions in a .py file?
Reveal answer
A saved script can be edited and run again later.
Try another case
Where does a change need to be saved so the next run of hello.py uses it?
Check your answer
Reveal answer
Save the change in the hello.py file that the terminal command runs.
Your progress
Reveal the check answer or reach the end to complete this lesson.