Hello World Project
Abstract
Writing a “Hello, World!” program is the traditional first step in learning any programming language. It looks trivial, but it teaches you four very real things at once: how to write source code, how to save it as a file your machine can find, how to run it through the Python interpreter, and how to read the output. In this tutorial we will go beyond just typing one line. We will explore why the program works, what happens when you press Enter, common errors beginners hit on their first day, and several small variations that take you from a single print statement to your first interactive program.
By the end of this tutorial you will be able to:
- Verify Python is installed on your computer.
- Create and save a
.py.pyfile. - Run a script from the terminal.
- Understand what
print()print()does and how Python evaluates a line of code. - Modify the program to take user input and respond.
Prerequisites
- Python 3.6 or above installed (download page).
- A text editor or IDE. We recommend Visual Studio Code with the official Python extension.
- A terminal you are comfortable opening (Command Prompt or PowerShell on Windows, Terminal on macOS/Linux).
- No previous programming experience required.
Before You Start
Open a terminal and confirm Python is on your PATH:
python --versionpython --versionYou should see something like Python 3.11.4Python 3.11.4. If you get “python is not recognized” on Windows, re-run the Python installer and check the “Add Python to PATH” option, then restart your terminal. On macOS/Linux you may need to use python3python3 instead of pythonpython.
Getting Started
Step 1 — Create a project folder
Keeping each project in its own folder is a habit worth forming on day one. It keeps your scripts organized and prevents naming clashes later.
- Choose a place on your disk, for example
DocumentsDocuments. - Create a new folder named
hello-worldhello-world. - Open the folder in your editor (in VS Code: File → Open Folder…).
Step 2 — Create the file
- In your editor, choose File → New File.
- Save it immediately with File → Save As… as
hello_world.pyhello_world.pyinside thehello-worldhello-worldfolder. - The
.py.pyextension is important — it tells the operating system and your editor that this is a Python file. Editors use the extension to enable syntax highlighting and Python tooling.
Step 3 — Write the code
Add the following code to hello_world.pyhello_world.py:
Hello World
Source# Hello World
print("Hello World")# Hello World
print("Hello World")Save the file again with Ctrl+S (or Cmd+S on macOS).
Step 4 — Run it
Open the integrated terminal in your editor (View → Terminal in VS Code) and run:
C:\Users\username\Documents\hello-world> python hello_world.py
Hello World!C:\Users\username\Documents\hello-world> python hello_world.py
Hello World!That Hello World!Hello World! line is your program’s output, printed to the screen by the Python interpreter.
How It Works
A Python source file is just a plain text file. When you type python hello_world.pypython hello_world.py, four things happen behind the scenes:
- The interpreter starts. Your operating system launches the
pythonpythonexecutable. - It reads your file top-to-bottom. Python parses the file into tokens (keywords, names, punctuation), then into an internal tree representation called an AST (Abstract Syntax Tree).
- It compiles to bytecode. The AST is compiled into a compact intermediate format. You may notice a
__pycache____pycache__folder appear next to your script — that is the cached bytecode. - It executes the bytecode. The Python virtual machine walks the bytecode, sees a call to the built-in
printprintfunction with the string"Hello World!""Hello World!", and writes that string to standard output — which your terminal then displays.
The whole pipeline is invisible. From your perspective: you saved a file, ran one command, and saw output. Everything else is Python’s job.
What does print()print() actually do?
printprint is a built-in function. You can call it with any value:
print("Hello World!") # a string
print(42) # an integer
print(3.14 * 2) # an expression that evaluates first
print("a", "b", "c") # multiple values separated by spacesprint("Hello World!") # a string
print(42) # an integer
print(3.14 * 2) # an expression that evaluates first
print("a", "b", "c") # multiple values separated by spacesBy default printprint appends a newline character (\n\n) after its output. You can change this with the endend keyword argument:
print("Hello", end=" ")
print("World!")
# Output: Hello World!print("Hello", end=" ")
print("World!")
# Output: Hello World!Common Mistakes
Beginners often hit one of these on day one. None of them are signs you are bad at programming — every Python developer has seen them.
| Problem | What you typed | What went wrong | Fix |
|---|---|---|---|
SyntaxError: Missing parentheses in call to 'print'SyntaxError: Missing parentheses in call to 'print' | print "Hello"print "Hello" | Python 2 syntax | Use print("Hello")print("Hello") |
NameError: name 'Hello' is not definedNameError: name 'Hello' is not defined | print(Hello)print(Hello) | Missing quotes — Python looked for a variable named HelloHello | Wrap strings in quotes: print("Hello")print("Hello") |
python: can't open file 'hello_world.py'python: can't open file 'hello_world.py' | Ran python hello_world.pypython hello_world.py from wrong folder | Terminal is in a different directory | cdcd into your project folder first |
| Nothing happens | Forgot to save the file | Editor still shows the dot meaning unsaved changes | Save with Ctrl+S before running |
IndentationErrorIndentationError | Pasted code with leading spaces | Python is whitespace-sensitive | Remove leading whitespace on top-level statements |
Variations to Try
Once your first program runs, modify it. Tweaking working code is the fastest way to learn.
1. Ask for a name
name = input("What is your name? ")
print("Hello,", name + "!")name = input("What is your name? ")
print("Hello,", name + "!")input()input()pauses the program, waits for the user to type something and press Enter, and returns whatever they typed as a string.name + "!"name + "!"joins two strings using the++operator (called string concatenation).
2. Use an f-string
F-strings are the modern, readable way to embed values inside strings:
name = input("Name: ")
print(f"Hello, {name}! Welcome to Python.")name = input("Name: ")
print(f"Hello, {name}! Welcome to Python.")The ff prefix tells Python: “this string contains expressions in curly braces — evaluate them and insert the result.”
3. Greet in multiple languages
print("Hello, World!")
print("Hola, Mundo!")
print("Bonjour le monde!")
print("こんにちは世界")print("Hello, World!")
print("Hola, Mundo!")
print("Bonjour le monde!")
print("こんにちは世界")Python source files are UTF-8 by default — non-Latin characters work out of the box.
4. Loop a greeting
for i in range(3):
print(f"Hello #{i + 1}")for i in range(3):
print(f"Hello #{i + 1}")This introduces the forfor loop and range()range() — two building blocks you will use in nearly every program.
Running Without the Terminal
If you prefer not to use the terminal:
- VS Code: click the ▶ run button in the top-right while
hello_world.pyhello_world.pyis open. - PyCharm: right-click the file in the project tree → Run ‘hello_world’.
- IDLE (bundled with Python): open the file and press F5.
All three do the same thing — they invoke python hello_world.pypython hello_world.py for you and capture the output in a panel.
Frequently Asked Questions
Why is it always “Hello, World!“? The phrase comes from Brian Kernighan’s 1972 tutorial for the B programming language and was popularized by the 1978 C Programming Language book. It became a tradition.
Do I need to compile Python like C or Java?
No. Python compiles to bytecode automatically the first time the file is run and caches it in __pycache____pycache__. You only run python hello_world.pypython hello_world.py.
What if I want to share this with someone who does not have Python installed? Look into PyInstaller or Nuitka — both can package a Python script into a standalone executable. That is far beyond Hello World, but good to know it is possible.
Educational Value
Even this tiny program teaches:
- File-based source code — the foundation of every real Python project.
- The print function — output is how programs communicate with humans.
- String literals — your first data type.
- Running an interpreter — the loop you will use thousands of times: edit, save, run, read output, fix.
- Reading errors — error messages are not punishments, they are clues.
Next Steps
You have a working Python development setup and you understand what happened when you ran your first program. From here, try one of the following:
- Modify the program to greet you by name.
- Move on to the next project, Simple Calculator, which introduces functions and basic arithmetic.
- Read about Python’s built-in functions —
printprintis just one of about seventy.
You can find the complete source code on GitHub.
Conclusion
A one-line program is not the goal. The goal is to make sure your environment works end-to-end: editor saves, interpreter runs, terminal shows output. Once that loop is reliable, every other project on Python Central Hub becomes easier. Celebrate this moment — every programmer alive started exactly where you are right now.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
