This guide walks you through writing and running your Python first program using the classic Hello World Python program example.
Writing your Python first program is an exciting milestone. It confirms that your Python environment is set up correctly and helps you understand how Python code is written, executed, and displayed on the screen.
In this tutorial, you will write and run a simple Python program, understand each line clearly, and learn how Python executes instructions behind the scenes.
Note: The Python Introduction page outlines the basics that prepare you for writing your first Python program.
1. What Is a Python Program?
A Python program is a collection of instructions written for the Python interpreter to execute. Each instruction tells Python to perform a specific task, such as displaying text, performing calculations, or processing data. Even the smallest Python program follows the same execution flow used by large real-world applications, making this first step extremely important. To put these ideas into practice, let’s start with the most common and beginner-friendly example used in Python.The Traditional First Python Program: “Hello, World!”
Most programming languages begin with a Hello, World! Python program. This program simply prints a message on the screen, helping beginners focus on syntax without distractions.Why “Hello, World!”?
- It verifies that Python is installed and working correctly
- It demonstrates Python’s simple syntax
- It produces immediate, visible output
- It builds confidence for beginners
2. Writing Your First Python Program
Step 1: Open Python
You can write your first program using any one of the following:
- Python Interactive Shell
- Command Prompt / Terminal
- IDLE (comes with Python)
- VS Code, PyCharm, or any code editor
Step 2: Type the Code
print("Hello, World!")
This single line is a complete and valid Python program. 3. Understanding Each Part of the Program
Let’s break the code down step by step.
i) print
print is a built-in Python function. Its job is to display output on the screen. Python provides many built-in functions, and print() is one of the most commonly used.
ii) Parentheses ()
Parentheses are used to pass information to a function. In this case, the information being passed to print() is the text you want to display.
iii) Double Quotes ” “
The text inside quotes is called a string. Strings represent textual data in Python.
"Hello, World!"
Python understands that anything inside quotes should be treated as text, not as code.
4. The Complete Instruction
print("Hello, World!")
This line tells Python:
“Display the text Hello, World! on the screen.” 5. Running the Python Program
If You Are Using the Python Shell
- Type the code
- Press Enter
Hello, World!
If You Are Using a Code Editor
- Save the file as first_program.py
- Open Command Prompt / Terminal
- Navigate to the file location
- Run:
python first_program.py
Output:
Hello, World! 6. How Python Executes This Program
Behind the scenes, Python follows this process:
- Reads the line of code
- Recognizes print() as a built-in function
- Identifies the string inside quotes
- Sends the string to the output screen
- Ends program execution
7. Common Beginner Mistakes (And How to Avoid Them)
Missing Quotes
Incorrect:print(Hello, World!)
Correct:
print("Hello, World!")
Text must always be enclosed in quotes.
Wrong Case for print
Incorrect:Print("Hello, World!")
Correct:
print("Hello, World!")
Python is case-sensitive.
Using Old Python Syntax
Incorrect (Python 2 style):print "Hello, World!"
Correct (Python 3):
print("Hello, World!") 8. Why This First Python Program Matters
This simple python program teaches several core Python concepts:
- Python uses readable, English-like syntax
- Programs are executed line by line
- Functions perform specific tasks
- Output can be displayed instantly
9. What’s Next?
Now that you’ve written your first Python program, the next step is to understand how Python handles:
- Statements and line breaks
- Indentation rules
- Variables and data types