Your First Python Program
Congratulations! 🎉 You've successfully set up your Python environment. Now it’s time to write your very first Python program — a crucial step that introduces you to how code is written, executed, and displayed in Python.
Chapter 1: Introduction to Python Programming
Sub-chapter: Your First Python Program
Congratulations! 🎉 You’ve successfully set up your Python environment. Now it’s time to write your very first Python program — a crucial step that introduces you to how code is written, executed, and displayed in Python.
🧭 Why Start with “Hello, World!”?
The “Hello, World!” program is the universal starting point for learning any programming language. It’s simple, but it demonstrates the entire development cycle — writing, saving, running, and seeing output.
Python’s beauty lies in how minimal this process is: one clean line of code can do the job.
🧑💻 Step 1: Open Your Development Environment
Open your preferred IDE (Integrated Development Environment) or text editor. Popular options include:
- VS Code – lightweight, fast, and customizable
- PyCharm – powerful IDE for large projects
- Jupyter Notebook – perfect for interactive experimentation
- IDLE – simple IDE that comes with Python by default
📄 Step 2: Create a New Python File
- In your IDE, create a new file.
- Save it with a
.pyextension — for example,hello_world.py.
This tells your system that the file contains Python code.
💡 Filenames should use lowercase letters and underscores (e.g.,
my_first_program.py) — avoid spaces or special characters.
🧩 Step 3: Write Your First Line of Code
Now, inside your file, type the following line:
print("Hello, World!")
This line instructs Python to display the message Hello, World! on the screen.
Let’s break it down:
print()→ a built-in Python function that outputs text to the console."Hello, World!"→ a string (a sequence of characters inside quotes).- The parentheses
()tell Python that we’re calling the function and passing it a value.
▶️ Step 4: Run Your Program
Method 1 – From IDE:
Most IDEs have a “Run” or “▶” button. Click it to execute your script.
The output should appear in the terminal or output panel:
Hello, World!
Method 2 – From Terminal:
- Open your terminal or command prompt.
- Navigate to the folder where your script is saved using
cd. - Run the following command:
python hello_world.py
or, depending on your system:
python3 hello_world.py
You’ll see:
Hello, World!
Congratulations — you’ve officially written and executed your first Python program! 🥳
🧠 Understanding What Just Happened
When you run your Python program:
- The interpreter reads your file line by line.
- It executes the command
print("Hello, World!"). - The output appears in your console window.
Python doesn’t require compilation like C++ or Java — it executes directly, making it perfect for rapid learning and experimentation.
✨ Try a Few Variations
Experimenting helps you understand syntax and behavior. Try these:
Printing multiple values:
print("Hello,", "World!")
Using variables:
message = "Hello, World!"
print(message)
Combining text and variables:
name = "Rambod"
print("Hello,", name, "!")
Using f-strings (modern Python syntax):
name = "Developer"
print(f"Hello, {name}! Welcome to Python.")
⚠️ Common Beginner Mistakes
| Mistake | Why It Happens | How to Fix |
|---|---|---|
print "Hello, World!" | Missing parentheses (Python 2 syntax) | Use print("Hello, World!") |
Print("Hello, World!") | Case-sensitive keywords | Use lowercase print |
| Missing quotes | Forgetting to wrap text in " " or ' ' | Always use quotes for strings |
🧩 Python is case-sensitive, meaning
🧾 Comments in Python
As your code grows, adding comments is essential. Comments are lines ignored by the interpreter — they help explain what your code does.
# This line prints a greeting message
print("Hello, World!")
Multi-line comment convention:
"""
This program prints a greeting message.
Created as the first example in our Python learning journey.
"""
print("Hello, World!")
💡 Challenge Yourself
Try modifying the message to make it more personal!
Examples:
print("Welcome to Python 3.12!")
print("My first script is running smoothly!")
Add emoji support (Python handles Unicode easily):
print("🚀 Hello, Python Universe! 🌍")
🧩 Key Takeaways
- Python code executes line by line through its interpreter.
- The
print()function outputs data to the console. - Syntax is minimal and highly readable.
- Comments help document your code.
- Always save files with
.pyand execute usingpython filename.py.
You’ve just written your very first Python program and learned how Python executes commands. From here, every concept you learn builds upon this small but powerful foundation — understanding input, output, and interaction with the interpreter.