Beginner

Hello World in Python

Your first Python program - the classic Hello World example with Docker setup

Every programming journey starts with Hello World. Python makes this incredibly simple—it’s just one line.

The Code

Create a file named hello.py:

1
print("Hello, World!")

That’s it. One line. This simplicity is what makes Python so beloved as a first programming language.

Understanding the Code

  • print() - A built-in function that outputs text to the console
  • "Hello, World!" - A string literal (text) enclosed in double quotes
  • No semicolons needed - Python uses newlines to separate statements
  • No boilerplate - Unlike Java or C, there’s no class or main function required

Running with Docker

The easiest way to run this without installing Python locally:

1
2
3
4
5
# Pull the official Python Alpine image (lightweight)
docker pull python:3.13-alpine

# Run the program
docker run --rm -v $(pwd):/app -w /app python:3.13-alpine python hello.py

Running Locally

If you have Python installed (Python 3.6+):

1
2
3
4
5
# Run directly
python hello.py

# Or on some systems
python3 hello.py

Expected Output

Hello, World!

Why Python is Different

Compare Python’s Hello World to other languages:

LanguageLines of CodeBoilerplate Required
Python1None
Java5Class, main method
C4includes, main function
C++5includes, namespace, main

This minimal boilerplate is a core Python philosophy: simple things should be simple.

Key Concepts

  1. Python is interpreted - No compilation step; source runs directly
  2. Indentation matters - Python uses whitespace to define code blocks (you’ll see this in later tutorials)
  3. Dynamic typing - No need to declare variable types
  4. Interactive mode - You can also run python and type print("Hello, World!") directly

The Interactive Shell

Python also has a REPL (Read-Eval-Print Loop). Try it:

1
docker run --rm -it python:3.13-alpine python

Then type:

1
2
3
>>> print("Hello, World!")
Hello, World!
>>> exit()

This interactive mode is great for experimenting and learning.

Running Today

All examples can be run using Docker:

docker pull python:3.13-alpine
Last updated:

Comments

Loading comments...

Leave a Comment

2000 characters remaining