Course Progress0% complete
🐍 Python Basics Topic 3 / 100
⏱ 7 min read

Your First Python Program

Write and run your very first lines of Python code. Understand what actually happens when you run a program.

"The first program you run is not just code — it is proof that you can do this. That proof matters."

— ShurAI

Hello World — The Tradition

Every programmer's first program is called "Hello World." It is a tradition going back to the 1970s — a simple program that prints a greeting to the screen. It exists to prove one thing: your setup works and you are ready to start.

In Python, Hello World is as simple as it gets:

python
print("Hello, World!")

Type this into a file called hello.py, save it, and run it with python3 hello.py. You should see:

output
Hello, World!

That is it. That is your first program. You just told a computer what to do, and it did it.

Understanding print()

The word print is a Python function — a built-in instruction that tells Python to display something on the screen. The parentheses () contain what you want to display. The quotes " " tell Python that the content inside is text.

You will use print() in almost every Python program you ever write. It is how your program communicates with you — showing results, messages, and data.

python
# Print a simple message
print("Hello, World!")

# Print a number
print(42)

# Print multiple items
print("My age is", 25)

# Print nothing — creates a blank line
print()

Your First Real Program

Now let's write something slightly more meaningful. A program that introduces you:

introduce.py
# My introduction program
# Change the values to match your own details

name   = "Rahul"
city   = "Mumbai"
age    = 22
goal   = "learn Python and AI"

print("--- My Introduction ---")
print(f"Name : {name}")
print(f"City : {city}")
print(f"Age  : {age}")
print(f"Goal : {goal}")
print("----------------------")

Run this file. You should see a neat, formatted introduction. Notice the f"..." syntax — that is an f-string, which lets you embed variables directly inside text. You will learn more about this in Topic 10.

What is a Variable?

Lines like name = "Rahul" create variables — named containers that store values. You will learn all about variables in Topic 5. For now, just know that variables let you store data and reuse it.

The Interactive Python Shell

Python has another way to run code: the interactive shell. Type python3 in your terminal (with no file name) and press Enter. You will see a prompt like >>>.

In the shell, you can type Python code one line at a time and see the result immediately:

python interactive shell
>>> print("Hello from the shell!")
Hello from the shell!

>>> 2 + 3
5

>>> name = "Priya"
>>> print(name)
Priya

>>> exit()    # type this to close the shell

The interactive shell is great for testing small ideas quickly. But for writing real programs, always use a .py file.

Understanding Errors

At some point — probably soon — you will see an error message. This is normal. Every programmer sees error messages every day. They are not failures. They are Python's way of telling you what needs to be fixed.

python — intentional error
# This will cause an error — the quote is not closed
print("Hello)
error output
SyntaxError: EOL while scanning string literal

Read error messages carefully. They tell you the type of error and the line number where it happened. Over time, you will learn to read them quickly and fix problems fast.

Never Be Afraid of Errors

Seeing an error does not mean you are bad at programming. It means Python found something it does not understand. Read the message, find the line, fix the issue. That process is how real coding works.

"Every error message is a teacher. The programmer who learns to read them clearly will always find their way through."

— ShurAI

🧠 Quick Check

What does the print() function do in Python?