Your First Python Program

In the last lesson, we learned about Python IDEs and editors. Now let’s write and understand our first Python program.

After learning Python IDEs and Editors, we compared editors and IDEs so we can pick a place to write code. Now let’s write our first real Python program.

This Is the Moment

Okay. We have Python installed. We have an editor. Now let’s write our first real program. And not just copy it. We are going to understand every single line. By the end of this article, we will be able to say — “I wrote a Python program. And I know exactly how it works.”

Let’s go.

The Classic First Python Program

Every programmer in the world starts with this one. It is a tradition. Like a rite of passage.

print("Hello, world!")

When we run it, we see:

Hello, world!

That’s it. That’s the whole program. Now let’s break it down. Piece by piece.

What Is the Python print() Function?

print is a function. A function is just a command that does something. We use it when we want the computer to do a specific job. The print function shows something on the screen.

Think of it like this. We are telling Python — “Hey, print this for me.” That’s it. Nothing complicated.

What Are the Parentheses in Python?

The parentheses ( ) hold what we want to print. Whatever we put inside the parentheses gets printed on the screen. Simple rule: print needs parentheses. Always.

What Are the Quotes in Python?

The quotes " " tell Python — “this is text, not code.” Text inside quotes is called a string. We will learn more about strings later. For now, let’s just remember — text goes in quotes.

What About the Exclamation Mark?

Nothing special. It is just part of the text. Python does not care. It is just a character like any other.

Let’s Try More print Statements

Open our editor. Create a file called first.py.

Type this:

print("Hello, world!")
print("My name is Alex")
print("I am learning Python")
print("This is my first program")

Save the file. Run it:

python first.py

Output

Hello, world!
My name is Alex
I am learning Python
This is my first program

Notice something? Each print goes on its own line. Python runs them one by one. Top to bottom. That is how it always works. No exceptions.

How to Print Numbers in Python

Yes. And here, we do not need quotes.

print(5)
print(100)
print(3.14)

Output

5
100
3.14

When we print numbers, no quotes needed. Just the number itself.

How to Do Math Inside Python print()

Absolutely. Watch this.

print(2 + 3)
print(10 - 4)
print(6 * 7)
print(20 / 5)

Output

5
6
42
4.0

Wait. Look at that last one. 20 / 5 gave 4.0, not 4. Why? Because division in Python always gives a decimal number. Always. Even if the answer is a whole number. We will talk about that more later. For now, let’s just remember — division gives us a decimal.

How to Mix Text and Numbers in Python print()

Yes. Just separate them with a comma.

print("My age is", 25)

Output

My age is 25

See how Python put a space between them automatically? That is helpful. We do not need to add the space ourselves.

Python print() Function: A Real-Life Example

Think of print like a loudspeaker. We have something to say. We speak into the loudspeaker. Everyone hears it. print is Python’s loudspeaker. Whatever we put inside it, the screen shows it.

And just like a loudspeaker, we can say one thing at a time. Then another thing. Then another. That is why each print is on its own line.

Common Mistakes in First Python Program

Let me save us some pain. These are mistakes that every beginner makes.

Mistake 1: Missing Quotes

If we write:

print(Hello)

Python will give an error:

NameError: name 'Hello' is not defined

Why? Because Hello without quotes is not a string. Python thinks it is a variable name. And it does not know any variable called Hello.

So what do we do? We add quotes.

print("Hello")

Mistake 2: Missing Parentheses

If we write:

print "Hello"

This will also give an error. In Python 3, parentheses are required. Always. No exceptions.

So what do we do? We add the parentheses.

print("Hello")

Mistake 3: Mixing Quotes Wrong

If we write:

print("Hello')

Notice — it starts with a double quote and ends with a single quote. That is a mismatch. Python will be confused.

So what do we do? We make sure the quotes match.

print("Hello")

Or:

print('Hello')

Both work. Just do not mix them.

Mistake 4: Forgetting to Save

We write code. We run it. Nothing changes. Why? Because we forgot to save the file. Always save before running. Always.

Let’s Make a Small Python Program

Here is a simple one. Let’s try it ourselves.

print("Welcome to my program")
print("----------------------")
print("This program was made by me")
print("Today I learned Python")
print("Thank you for reading")

Run it. See the output? See how the lines appear one by one? We made that. We wrote those instructions. The computer followed them. That is programming.

It feels good, right?

Let’s Try One More Python Program

This one uses everything we learned.

print("My name is Alex")
print("I am", 25, "years old")
print("Next year I will be", 25 + 1)
print("That is all for now")

Output

My name is Alex
I am 25 years old
Next year I will be 26
That is all for now

See what happened there? Python did the math for us. 25 + 1 became 26. We gave it a calculation. It calculated. It showed the result. That is the power of programming. We tell the computer what to do. It does it.

Next, we will learn about Python Syntax Basics so we can continue step by step.