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:


📄 Step 2: Create a New Python File

  1. In your IDE, create a new file.
  2. Save it with a .py extension — 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:


▶️ 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:

  1. Open your terminal or command prompt.
  2. Navigate to the folder where your script is saved using cd.
  3. 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:

  1. The interpreter reads your file line by line.
  2. It executes the command print("Hello, World!").
  3. 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

MistakeWhy It HappensHow to Fix
print "Hello, World!"Missing parentheses (Python 2 syntax)Use print("Hello, World!")
Print("Hello, World!")Case-sensitive keywordsUse lowercase print
Missing quotesForgetting to wrap text in " " or ' 'Always use quotes for strings

🧩 Python is case-sensitive, meaning Print, PRINT, and print are three different things.


🧾 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


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.