Hello, World! in Python: A Short History and Your First Program

Programming ·

Python is often recommended as the best first programming language, and it’s also one of the most used by professionals, in everything from websites to data science and artificial intelligence. Its “Hello, World!” is a single line. Here’s where Python came from, and how to write and run your first program.

A short history of Python

In December 1989, Dutch programmer Guido van Rossum was working at CWI, a research institute in Amsterdam. Looking for a project to keep him busy over the Christmas holidays, he started writing a new programming language that would be easy to read and quick to write, while still being powerful enough for real work.

He named it Python, not after the snake but after the British comedy show Monty Python’s Flying Circus, which he was a fan of. The first version was released publicly in February 1991. Python’s documentation and examples still often use “spam” and “eggs” in place of the more usual “foo” and “bar,” a nod to a famous Monty Python sketch.

Python’s design puts readability first. Most languages use symbols like curly braces to group code, but Python uses indentation, so code has to be laid out neatly to work at all. That philosophy is summed up in “The Zen of Python,” a list of guiding principles you can read by typing import this into Python.

Python 2.0 arrived in 2000, and Python 3.0 in 2008. Python 3 fixed long-standing problems but wasn’t fully compatible with Python 2, so the switch took the community more than a decade; Python 2 was officially retired on January 1, 2020. Van Rossum led the language as its “Benevolent Dictator For Life” until 2018, when he stepped back and handed decisions to an elected steering council.

The code

print("Hello, World!")

That’s the whole program. print is a built-in function that writes text to the screen, and the text in quotes is a string. In Python, single and double quotes both work.

If you see older examples written as print "Hello, World!" without parentheses, that’s Python 2 and won’t work in Python 3.

Steps to run it

1. Install Python

  • Windows: download Python from python.org and run the installer. If it offers an “Add python.exe to PATH” option, tick it, so you can run Python from the terminal.
  • Mac: download the installer from python.org, or use Homebrew (brew install python).
  • Linux: Python 3 is usually already installed. If not, install it with your package manager, for example sudo apt install python3 on Ubuntu or Debian.

Open a terminal (Terminal on Mac, PowerShell or Command Prompt on Windows) and check it worked:

python3 --version

On Windows, use python --version (or py --version) instead; python3 may not be available there.

2. Save the program

Save the one line of code in a file called hello.py. Any plain text editor works; free code editors like Visual Studio Code make it easier, with colors and error highlighting.

3. Run it

In the terminal, go to the folder where you saved it and run it:

cd path/to/your/folder
python3 hello.py

(On Windows: python hello.py or py hello.py.) The terminal prints:

Hello, World!

Or try it interactively

Python also has an interactive mode, where you type code and see the result straight away. Run python3 (or python on Windows) with no file name, and you’ll see a >>> prompt:

>>> print("Hello, World!")
Hello, World!

Type exit() or press Ctrl + D (Ctrl + Z then Enter on Windows) to leave.

Hello, World! in other languages