Python First Program: Write and Run Your First Python Program

This guide walks you through writing and running your Python first program using the classic Hello World Python program example.

Writing your Python first program is an exciting milestone. It confirms that your Python environment is set up correctly and helps you understand how Python code is written, executed, and displayed on the screen.

In this tutorial, you will write and run a simple Python program, understand each line clearly, and learn how Python executes instructions behind the scenes.

Note: The Python Introduction page outlines the basics that prepare you for writing your first Python program.

1. What Is a Python Program?

A Python program is a collection of instructions written for the Python interpreter to execute. Each instruction tells Python to perform a specific task, such as displaying text, performing calculations, or processing data. Even the smallest Python program follows the same execution flow used by large real-world applications, making this first step extremely important. To put these ideas into practice, let’s start with the most common and beginner-friendly example used in Python.

The Traditional First Python Program: “Hello, World!”

Most programming languages begin with a Hello, World! Python program. This program simply prints a message on the screen, helping beginners focus on syntax without distractions.

Why “Hello, World!”?

  • It verifies that Python is installed and working correctly
  • It demonstrates Python’s simple syntax
  • It produces immediate, visible output
  • It builds confidence for beginners

2. Writing Your First Python Program

Step 1: Open Python

You can write your first program using any one of the following:

  • Python Interactive Shell
  • Command Prompt / Terminal
  • IDLE (comes with Python)
  • VS Code, PyCharm, or any code editor
For beginners, IDLE or the Python shell is the easiest place to start.

Step 2: Type the Code

print("Hello, World!")
This single line is a complete and valid Python program.

3. Understanding Each Part of the Program

Let’s break the code down step by step.

i) print

print is a built-in Python function. Its job is to display output on the screen. Python provides many built-in functions, and print() is one of the most commonly used.

ii) Parentheses ()

Parentheses are used to pass information to a function. In this case, the information being passed to print() is the text you want to display.

iii) Double Quotes ” “

The text inside quotes is called a string. Strings represent textual data in Python.

"Hello, World!"

Python understands that anything inside quotes should be treated as text, not as code.

4. The Complete Instruction

print("Hello, World!")
This line tells Python: “Display the text Hello, World! on the screen.”

5. Running the Python Program

If You Are Using the Python Shell

  1. Type the code
  2. Press Enter
Output:
Hello, World!

If You Are Using a Code Editor

  1. Save the file as first_program.py
  2. Open Command Prompt / Terminal
  3. Navigate to the file location
  4. Run:
python first_program.py
Output:
Hello, World!

6. How Python Executes This Program

Behind the scenes, Python follows this process:

  1. Reads the line of code
  2. Recognizes print() as a built-in function
  3. Identifies the string inside quotes
  4. Sends the string to the output screen
  5. Ends program execution
Even though the program is small, the execution process is exactly the same as larger Python applications.

7. Common Beginner Mistakes (And How to Avoid Them)

Missing Quotes

Incorrect:
print(Hello, World!)
Correct:
print("Hello, World!")
Text must always be enclosed in quotes.

Wrong Case for print

Incorrect:
Print("Hello, World!")
Correct:
print("Hello, World!")
Python is case-sensitive.

Using Old Python Syntax

Incorrect (Python 2 style):
print "Hello, World!"
Correct (Python 3):
print("Hello, World!")

8. Why This First Python Program Matters

This simple python program teaches several core Python concepts:

  • Python uses readable, English-like syntax
  • Programs are executed line by line
  • Functions perform specific tasks
  • Output can be displayed instantly
Mastering this step makes learning variables, conditions, loops, and functions much easier.

9. What’s Next?

Now that you’ve written your first Python program, the next step is to understand how Python handles:

  • Statements and line breaks
  • Indentation rules
  • Variables and data types
These concepts will help you move from simple print statements to real-world programs.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top