Now that Python is installed on your system, it is time to write your first proper Python program. This article will help you understand how Python executes code step by step.
1. What is a Python Program?
A Python program is a file that contains Python instructions. These instructions are executed by the Python interpreter.
Python files always end with .py
2. Creating Your First Python File
- Open VS Code
- Click File → New File
- Save as first_program.py
Now write the following code:
print("Hello World")
3. Running the Program
Right click inside the file and choose Run Python File.
Output:
Hello World
Congratulations 🎉 You just wrote your first Python program.
4. How Python Executes Code
Let us understand what happens internally.
- Python reads code from top to bottom
- It executes one line at a time
- It prints the message on screen
Python does not skip lines randomly. It follows order.
5. Adding Multiple Lines
Now modify your program like this:
print("Hello World")
print("Welcome to Python")
print("This is my first program")
Output:
Hello World Welcome to Python This is my first program
Each print statement executes one after another.
6. Understanding Errors
If you forget quotation marks:
print(Hello World)
You will get an error.
Python shows error because text must be inside quotes.
Errors are normal in programming. Do not panic when you see errors.
7. Real-World Example
In real applications, programs are much larger. But they follow the same structure:
- Write instructions
- Save file with .py
- Run the file
- Fix errors if any
Every big software started from simple programs like this.
8. Comparison – Interactive Mode vs Script Mode
Interactive Mode
- Used in command prompt
- Good for quick testing
- Temporary execution
Script Mode
- Saved as .py file
- Used for projects
- Professional method
9. Pros and Cons of Script Files
Pros
- Reusable
- Professional
- Easy to manage large programs
Cons
- Need to save properly
- Must manage file names carefully
Conclusion
In this article, you learned:
- What is a Python program
- How to create .py file
- How to run a program
- How Python executes code
- Difference between interactive and script mode
This is your first real step into programming.
In the next article, we will understand Output and print() function in detail.
Your Zero to Hero journey is growing stronger 🚀