You have Python installed and an editor ready. The next step is to write a small Python file, run it, and see the result. This is the basic loop you will repeat thousands of times while learning.
If you have not installed Python yet, go back to the installation guide. If you need an editor, see the editor comparison first.
Create a Python file
Open your editor and create a new file. Save it as hello.py in a folder you can find easily, such as a python-practice folder on your desktop or in your home directory.
The .py extension tells your editor and your operating system that this file contains Python code. Without it, syntax highlighting and other editor features may not work.
Type this single line into the file:
print("Hello, World!")Save the file. That is your first Python program.
The print() function sends whatever is inside the parentheses to the terminal. The double quotes around Hello, World! make it a string, which is how Python represents text.
Run the program from the terminal
Open a terminal and navigate to the folder where you saved hello.py. For example, if you saved it on your desktop:
cd ~/Desktop/python-practiceNow run the file with Python:
python hello.pyIf your system uses python3 instead of python, use that:
python3 hello.pyYou should see this output:
Hello, World!If you do, congratulations. You just wrote and ran a Python program.
If you see an error instead, do not worry. Read the error message. Common first-time issues include:
python: command not found-- Python is not installed or not on your PATH. Go back to the installation guide.can't open file 'hello.py'-- You are not in the right folder, or the filename has a typo. Usels(macOS/Linux) ordir(Windows) to see what files are in the current folder.SyntaxError-- Check that your code matches the example exactly, including the parentheses and quotes.
Run the program from your editor
Most editors let you run a Python file without leaving the editor. In VS Code, open the file, then click the play button in the top-right corner, or press Ctrl+F5 (Windows) or Cmd+F5 (macOS) to run without debugging.
In PyCharm, right-click the file tab and choose "Run 'hello'".
In IDLE, open the file and press F5, or use the menu: Run > Run Module.
The output appears in a terminal or output panel inside the editor. The result is the same as running it from the terminal directly.
Pick one way to run your code and stick with it for now. Switching between terminal and editor buttons is fine when you want to compare, but using one approach consistently helps you build muscle memory.
Try a few variations
Now that the basic loop works, experiment with small changes. Modify hello.py to print a few more lines:
print("Hello, World!")
print("My name is Python.")
print("I run one line at a time.")Save and run again. You will see three lines of output, each on its own line:
Hello, World!
My name is Python.
I run one line at a time.Python runs statements in order, from top to bottom. Each print() call adds a new line at the end by default.
Try printing a number:
print(42)
print(3 + 4)You do not need quotes around numbers. print(3 + 4) prints 7 because Python calculates the sum before printing.
What happens when you run a Python file
When you type python hello.py, here is what happens behind the scenes:
- Python reads the file from disk.
- It parses the code to check for syntax errors.
- If the syntax is valid, Python compiles the code into bytecode.
- The Python Virtual Machine executes the bytecode, line by line.
- Each
print()call writes text to the terminal. - When the last line finishes, Python exits.
For a deeper look at this process, read how Python runs your code.
Next steps
Now that you can write and run a Python file, you are ready to learn a few more things that make day-to-day coding easier. The next articles cover how Python executes your code, how to install third-party packages, and how to structure your first project.
Once you are comfortable running scripts, spend a few minutes trying different print() statements. Change the message. Print a few numbers. Make a deliberate typo and see what the error looks like. The more you practice this small loop, the faster the rest of Python will feel natural.
Rune AI
Key Insights
Save Python code in files ending with .py; Use python filename.py to run a script in the terminal; print() is your first tool for seeing program output; Error messages are helpful clues, not failures.
Frequently Asked Questions
What is the simplest Python program I can write?
Why does my Python file not run when I double-click it?
What does print() actually do?
My terminal shows an error when I run my script. Is that normal?
Conclusion
Running your first program means you have a working Python setup. The loop of writing code, running it, reading output, and fixing errors is the core of learning Python.
More in this topic
Create and Assign Variables in Python
Learn every way to create and assign variables in Python, from basic single assignment to expressions, type hints, and practical patterns beginners use every day.
Python Variable Naming Rules
Learn Python's variable naming rules, including allowed characters, reserved keywords, PEP 8 conventions, and how to choose names that make your code readable.
Python Variables Explained
Understand what Python variables are, how they store and reference data, and why Python's variable model is different from other programming languages.