Writing Your First Python Program

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

Example: hello.py

2. Creating Your First Python File

  1. Open VS Code
  2. Click File → New File
  3. 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 🚀

Chakrapani U

Hi, I’m Chakrapani Upadhyaya, an IT professional with 15+ years of industry experience. Over the years, I have worked on web development, enterprise applications, database systems, and cloud-based solutions. Through this blog, I aim to simplify complex technical concepts and help learners grow from beginners to confident, industry-ready developers.

Previous Post Next Post

نموذج الاتصال