Every programmer, in every language, starts in the same place: printing the words "Hello, World!" to a screen. It looks trivial, and in a sense it is — but it's also the first real checkpoint in learning to code. This article walks through your first python program from writing it to running it three different ways, then builds it into something a little more interactive.
Introduction: Why "Hello, World!"?
The python hello world tradition goes back decades, to an early programming tutorial for the C language in the 1970s. It caught on because it's the perfect minimal test: short enough to type in seconds, but complete enough to prove something real.
What it actually proves is two things:
Your environment works. Python is installed correctly, your editor or terminal can find it, and code you write actually executes.
You understand the absolute basics of syntax — how to call a function, how to write a string, and how a Python file gets run.
Every language has its own version of this ritual. Getting through it in Python is the first small win in a much longer learning path.
Writing Your First Python File
Creating the file
Open your editor of choice — VS Code, PyCharm, or even IDLE (Python's bundled basic editor) all work fine here — and create a new file. Save it with a .py file extension, for example:
hello.py
That extension matters. It tells your editor (and your operating system) that this is a Python source file, which enables syntax highlighting, run buttons, and other Python-specific tooling.
The code
Inside that file, type exactly this:
# This is a comment — Python ignores this line when running
print("Hello, World!")
Save the file. That's the whole program.
Breaking down the line
print()is a built-in Python function whose job is to display output to the screen. Whatever you put inside the parentheses gets printed."Hello, World!"is a string — a sequence of text characters. In Python, strings are wrapped in quotation marks.Quote rules: Python accepts either single quotes (
'Hello, World!') or double quotes ("Hello, World!") — they're functionally identical. The only rule is that the opening and closing quote must match. Pick one style and stay consistent; double quotes are the more common convention in most style guides.
Running Your Program Three Ways
Writing the file is half the job — now you need to actually run it. Here are three ways to do that.
From the terminal or command line
Open a terminal, navigate to the folder containing your file, and run:
python hello.py
On macOS and Linux, you'll usually need python3 instead, since the bare python command may not point to Python 3:
python3 hello.py
You should see:
Hello, World!
printed directly in your terminal.
From an IDE
If you're working in VS Code, open the file and click the Run (▶) button in the top-right corner of the editor — it runs the file in an integrated terminal and shows the output right there.
In PyCharm, right-click anywhere in the editor and choose Run 'hello', or use the green play button that appears in the gutter next to your code. PyCharm opens a Run panel at the bottom of the window with the output.
Both editors are essentially doing the same thing under the hood: calling the Python interpreter on your file, the same way the terminal command does — they just handle it for you with a click.
From the REPL directly
You can also skip the file entirely and type the line straight into the REPL, the interactive shell covered in the previous article in this series:
>>> print("Hello, World!")
Hello, World!
This works instantly, but remember: nothing typed into the REPL is saved. It's great for testing a line quickly, but your actual program should live in a .py file you can run again later.
Making It More Interactive
Once you've got the basic version working, it's worth extending it slightly — this is where Python starts to feel like an actual program instead of a single command.
Getting input from the user
The input() function pauses your program and waits for the person running it to type something:
# Ask the user for their name
name = input("What's your name? ")
# Use it in a greeting
print("Hello, " + name + "!")
Whatever the user types gets stored in the name variable as a string, ready to use.
Introducing f-strings
That print("Hello, " + name + "!") line works, but string concatenation with + gets clunky fast, especially once you're combining several pieces of text and variables. Python's f-strings solve this cleanly. An f-string is a string prefixed with the letter f, where you can drop variables directly inside curly braces:
name = input("What's your name? ")
# f-string: cleaner than concatenation
print(f"Hello, {name}!")
This is the standard, modern way to combine text and variables in Python, and you'll see it constantly in real code.
A quick note on sep and end
print() has two optional parameters worth knowing early:
# sep controls what goes between multiple arguments (default is a space)
print("Hello", "World", sep=", ") # Hello, World
# end controls what's printed after the output (default is a newline)
print("Hello, World!", end=" ")
print("Nice to see you.")
# Output: Hello, World! Nice to see you.
You won't need these constantly, but they're useful the moment you want tighter control over how output is formatted.
Common Beginner Mistakes & Next Steps
A few errors show up constantly at this stage — recognizing them quickly will save you a lot of confusion.
Mismatched quotes. Starting a string with
"and closing it with'will throw a syntax error. Keep your opening and closing quote characters identical.Forgetting the parentheses on
print. In Python 3,printis a function, not a statement —print "Hello"(no parentheses) is Python 2 syntax and will raise an error in Python 3. Always useprint("Hello").Indentation issues. Python uses indentation, not curly braces, to define blocks of code. Mixing tabs and spaces, or indenting a line that shouldn't be indented, is one of the most common early errors — and the error messages around it can be confusing until you get used to reading them.
Keep experimenting
The best way to build confidence at this stage is to mess with what you've already got:
Change the greeting text.
Add a second and third
print()statement.Ask for more than one piece of input — maybe a name and a favorite color — and combine them into a sentence.
If you already know a little about loops, try wrapping your greeting in one and see what happens.
None of this needs to be "correct" or elegant yet. The goal right now is just getting comfortable typing Python and watching it respond.
What's next
With your first working program under your belt, the natural next step is understanding variables and data types in more depth — how Python stores numbers, text, and other kinds of information, and how those types behave differently from each other. That's where the next article in this series picks up.