Skip to content

Hello World Project

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 file.
  • Run a script from the terminal.
  • Understand what print() does and how Python evaluates a line of code.
  • Modify the program to take user input and respond.
  • 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.

Open a terminal and confirm Python is on your PATH:

check-python
python --version

You should see something like Python 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 python3 instead of python.

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.

  1. Choose a place on your disk, for example Documents.
  2. Create a new folder named hello-world.
  3. Open the folder in your editor (in VS Code: File → Open Folder…).
  1. In your editor, choose File → New File.
  2. Save it immediately with File → Save As… as hello_world.py inside the hello-world folder.
  3. The .py extension 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.

Add the following code to hello_world.py:

Hello World pch.viewSource
Hello World
# Hello World
print("Hello World")

Save the file again with Ctrl+S (or Cmd+S on macOS).

Open the integrated terminal in your editor (View → Terminal in VS Code) and run:

command
C:\Users\username\Documents\hello-world> python hello_world.py
Hello World!

That Hello World! line is your program’s output, printed to the screen by the Python interpreter.

A Python source file is just a plain text file. When you type python hello_world.py, four things happen behind the scenes:

  1. The interpreter starts. Your operating system launches the python executable.
  2. 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).
  3. It compiles to bytecode. The AST is compiled into a compact intermediate format. You may notice a __pycache__ folder appear next to your script — that is the cached bytecode.
  4. It executes the bytecode. The Python virtual machine walks the bytecode, sees a call to the built-in print function with the string "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.

print is a built-in function. You can call it with any value:

print-examples
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 spaces

By default print appends a newline character (\n) after its output. You can change this with the end keyword argument:

end-arg
print("Hello", end=" ")
print("World!")
# Output: Hello World!

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.

ProblemWhat you typedWhat went wrongFix
SyntaxError: Missing parentheses in call to 'print'print "Hello"Python 2 syntaxUse print("Hello")
NameError: name 'Hello' is not definedprint(Hello)Missing quotes — Python looked for a variable named HelloWrap strings in quotes: print("Hello")
python: can't open file 'hello_world.py'Ran python hello_world.py from wrong folderTerminal is in a different directorycd into your project folder first
Nothing happensForgot to save the fileEditor still shows the dot meaning unsaved changesSave with Ctrl+S before running
IndentationErrorPasted code with leading spacesPython is whitespace-sensitiveRemove leading whitespace on top-level statements

Once your first program runs, modify it. Tweaking working code is the fastest way to learn.

hello_user.py
name = input("What is your name? ")
print("Hello,", name + "!")
  • input() pauses the program, waits for the user to type something and press Enter, and returns whatever they typed as a string.
  • name + "!" joins two strings using the + operator (called string concatenation).

F-strings are the modern, readable way to embed values inside strings:

f-string.py
name = input("Name: ")
print(f"Hello, {name}! Welcome to Python.")

The f prefix tells Python: “this string contains expressions in curly braces — evaluate them and insert the result.”

multilang.py
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.

loop.py
for i in range(3):
    print(f"Hello #{i + 1}")

This introduces the for loop and range() — two building blocks you will use in nearly every program.

If you prefer not to use the terminal:

  • VS Code: click the ▶ run button in the top-right while hello_world.py is 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.py for you and capture the output in a panel.

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__. You only run python 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.

Running the file exactly as it ships takes 0.1 s and prints:

python helloworld.py
Hello World

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.

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 functionsprint is just one of about seventy.

You can find the complete source code on GitHub.

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.

diagram Diagram mermaid
  • print is a function, not a statement. In Python 2 print "hi" was valid syntax; in Python 3 it is a SyntaxError. Every tutorial older than 2020 that you copy from is a candidate for this one.
  • Output is buffered when it is not going to a terminal. Run this file and the text appears instantly; pipe it into another program and it may appear only when the process exits. That is why print(..., flush=True) exists, and why the stderr line in the exercise below comes out first — stderr is unbuffered.
  • print converts, it does not format. print([1, 2, 3]) shows the list’s repr, and print(0.1 + 0.2) shows 0.30000000000000004, because that genuinely is the nearest float to 0.3.
  • The file has no if __name__ == "__main__": guard. For one line that is fine, but it means importing this module prints. Every project past this one in the section has the guard, and the reason is exactly that.
  • The whole program is one line, and it runs in 0.094 s on this machine — almost all of that is interpreter startup, not the print.
  • print(*args, sep=" ", end="\n", file=sys.stdout) — all three keyword arguments are what make it more than sys.stdout.write.
  • Writing to sys.stderr keeps a message out of a redirected stdout.
  • print is a thin wrapper: file.write(sep.join(map(str, args)) + end) reproduces it exactly.
pch.quizTag pch.quizDefaultTitle
  1. What is the difference between print('a', 'b') and print('a' + 'b')?

    pch.quizShowAnswer

    B — The first passes two arguments and joins them with sep (a space by default); the second passes one already-joined string

  2. Why might output written with print appear late, or out of order with error messages?

    pch.quizShowAnswer

    B — stdout is buffered when it is not attached to a terminal, while stderr is not — so the two streams can interleave differently than the source order

  3. print(0.1 + 0.2) shows 0.30000000000000004. What is wrong?

    pch.quizShowAnswer

    B — Nothing is wrong with print — 0.1 and 0.2 have no exact binary representation, so their sum is the nearest float, and print is showing it honestly

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading