Your First Python Program: Hello World Explained Line by Line
Your First Python Program: Hello World Explained Line by Line
Introduction
In the previous post, we successfully installed Python on our system. Now it’s time to write our first Python program.
Don’t worry if you are new — this post is written for absolute beginners.
---What is a Hello World Program?
A Hello World program is the first program most people write when learning a new programming language.
Its purpose is simple:
- Check if the language is installed correctly
- Understand basic syntax
- Gain confidence
Your First Python Program
Here is the simplest Python program:
print("Hello World")
This single line is a complete Python program.
---Line-by-Line Explanation
1️⃣ print
print is a built-in Python function.
It is used to display output on the screen.
2️⃣ Parentheses ( )
The parentheses tell Python that we are calling a function. Whatever is written inside them will be processed by Python.
3️⃣ "Hello World"
This is a string (text) that we want Python to display. Text is always written inside quotation marks.
Print the text "Hello World" on the screen.
How to Run This Program
Method 1: Using Python Interactive Mode
1. Open Command Prompt (Windows) or Terminal (Mac)
2. Type python or python3
3. Type the program and press Enter
print("Hello World")
Method 2: Using a Python File
1. Open any text editor
2. Save the file as hello.py
3. Write the program inside the file
4. Run it using the command:
python hello.py
Common Beginner Mistakes
- Forgetting quotation marks ❌
- Using
Printinstead ofprint❌ - Missing parentheses ❌
print is correct, but Print is wrong.
What You Learned in This Post
- What a Hello World program is
- How to write your first Python program
- How Python executes a line of code
What’s Next?
Now that you have written your first program, it’s time to learn how Python stores data.
Next Post: Python Basics – Variables Explained with Examples
---Contact Information
👋 About the Author
Ayush Gupta
MSc AI/ML Student | Machine Learning & Python Enthusiast
📧 Email:
aygupta9898@gmail.com
Comments
Post a Comment