Your First Python Programs
Your First Python Program: Hello World
5 min read
A tradition as old as programming itself
In 1978, computer scientists Brian Kernighan and Dennis Ritchie published a book on the C programming language. Their very first example program was one that printed the words "Hello, world!" to the screen.
The tradition stuck. Today, almost every programming course, tutorial, and textbook begins with the same program — not because it's impressive, but because it proves the system works. If "Hello, world!" runs, your installation is correct, your tools are working, and you're ready to learn.
Let's write it.
The program
print("Hello, world!")
That's the entire program. One line.
What happens when you run it:
Hello, world!
Understanding what just happened
Even in one line, there's a lot to understand.
print()
print() is a function — a built-in command that Python already knows how to handle. When Python sees print(), it knows: "display whatever is inside those parentheses."
Functions in Python always have parentheses () after their name. You'll learn much more about functions in a later lesson.
"Hello, world!"
The text inside the parentheses is called a string — a piece of text that Python treats as data. Strings are always wrapped in either double quotes "..." or single quotes '...'. Both work.
The string tells print() what to display.
Putting it together
print( "Hello, world!" )
^ ^
| |
function what to print
Python reads from left to right: "Call the print function with the argument 'Hello, world!' ". The function does its job — displaying the text — and the program finishes.
Running your program: three options
Option A — The terminal
- Open a plain text editor (Notepad on Windows, TextEdit on Mac) or your IDE
- Type
print("Hello, world!") - Save the file as
hello.py(the.pyextension tells your computer this is a Python file) - Open your terminal, navigate to where you saved the file, and type:
python hello.py - Press Enter. You'll see
Hello, world!appear.
Option B — Your IDE (VS Code, PyCharm, Thonny)
- Open your IDE and create a new file
- Type
print("Hello, world!") - Save as
hello.py - Click the Run button (usually a green triangle ▶)
- The output appears in the built-in terminal panel at the bottom
Option C — Google Colab (no installation)
- Go to colab.research.google.com and sign in with a Google account
- Click + Code to add a new code cell
- Type
print("Hello, world!") - Click the play button ▶ to the left of the cell
- The output appears immediately below
Experimenting: what happens if you change things?
The best way to learn is to try variations and see what happens.
Print a different message
print("Hello, Python!")
Print multiple lines
print("Hello, world!")
print("My name is Alex.")
print("I'm learning Python.")
Output:
Hello, world!
My name is Alex.
I'm learning Python.
Each print() call produces one line of output.
What happens if you remove the quotes?
print(Hello, world!)
Output:
SyntaxError: invalid syntax
Python throws an error because without quotes, it doesn't know whether Hello and world are text or the names of variables. The quotes are how you tell Python: this is text, treat it as-is.
What if you use single quotes instead?
print('Hello, world!')
This works perfectly. Single quotes and double quotes are interchangeable for strings in Python.
Comments: notes in your code
Python ignores any line that starts with #. These are called comments — notes for humans that explain what the code does.
# This program prints a greeting
print("Hello, world!")
Comments help you remember what your code does when you come back to it later, and they're useful for explaining your thinking to someone else reading your code.
A slightly more personal version
The workbook example takes this one step further by using a variable:
# Hello World example in Python
print("Hello, world!")
# Real-life idea: use Python to generate messages, greet users, or log application start-up text.
You can customize the message to make it your own:
print("Hello! My name is Alex and I just ran my first Python program.")
Every piece of software you've ever used — apps, websites, games — started with something this simple. The complexity comes later. Today, you've written a working program.
Key takeaway
print() is Python's built-in command for displaying output. Strings (text) go inside quotes. Running your first Python program — even a one-liner — confirms that your setup works and that you understand the basic structure of a Python instruction.
What's next?
"Hello, world!" is satisfying, but programs that can only display fixed text are limited. In the next lesson, you'll learn about variables — the way Python stores and works with information that can change.