Python Basics for Absolute BeginnersLesson 1 of 58 min read

Run Your First Python Program

Install Python, try the interactive shell, run your first script with print() and read your first error.

Python is one of the most popular first programming languages because its code reads almost like plain English. In this course you’ll go from zero to writing a small quiz game. No previous experience is needed, just a computer and about an hour per lesson.

In this first lesson, you’ll install Python, run code two different ways and meet your first error message.

Step 1: Get Python

Python is free and open source. The official site, python.org, has installers for Windows and macOS, and most Linux systems already include Python 3.

  • Windows and macOS: download the latest Python 3 installer from python.org/downloads and follow the steps. On Windows, the installer offers an option to add Python to your PATH; turning it on makes running Python from the command line easier.
  • Linux: open a terminal and type python3 --version. If you see a version number, you’re ready.
  • School computer or Chromebook? Ask whether Python is already installed, or use a free online Python editor for now. Everything in this course works in any standard Python 3.

The python.org installers for Windows and macOS also include IDLE, a simple editor made for beginners. This course uses IDLE in examples, but any editor works.

Step 2: Try the interactive shell

Open IDLE (or type python3 in a terminal; on Windows it may be python or py). You’ll see a prompt like >>>. This is the interactive shell: you type one line, press Enter and Python answers immediately.

Try these:

>>> 2 + 3
5
>>> 10 / 4
2.5
>>> print("Hello, world!")
Hello, world!

The shell is great for experiments. If you’re not sure what something does, try it here first.

Step 3: Write a script

The shell forgets everything when you close it. To save your work, write a script: a text file ending in .py.

In IDLE, choose File → New File, type the following, and save it as hello.py:

# My first Python program
print("Hello! I'm learning Python.")
print("2 + 3 =", 2 + 3)

Run it with Run → Run Module (or press F5). In a terminal, you’d run python3 hello.py. The output appears:

Hello! I'm learning Python.
2 + 3 = 5

A few things to notice:

  • print() is a function. It displays whatever you put inside the brackets.
  • Text goes inside quotes. That’s called a string. Numbers don’t need quotes.
  • When you give print() several items separated by commas, it prints them with a space between.
  • Lines starting with # are comments. Python ignores them; they’re notes for humans.

Step 4: Meet your first error

Errors are a normal part of programming. Everyone gets them constantly. Change your script so a quote is missing:

print("Hello!)

Run it, and Python stops with a message similar to:

SyntaxError: unterminated string literal

The exact wording varies between Python versions, but it tells you what kind of error happened and roughly where. Read error messages from the bottom up: the last line names the problem, and the lines above point to the line number.

Try another one:

prnt("Hello")
NameError: name 'prnt' is not defined

Python doesn’t know a function called prnt. Recent versions often suggest what you probably meant. Fix the typo and run again.

A tiny practice task

Write a script called about_me.py that prints three lines: your first name, your favourite food and the result of a calculation, such as the number of minutes in a week (7 * 24 * 60).

print("Name: Sam")
print("Favourite food: dumplings")
print("Minutes in a week:", 7 * 24 * 60)

The last line prints Minutes in a week: 10080.

Key takeaways

  • Python is free; get it from python.org or use the one already on your system.
  • The interactive shell (>>>) runs one line at a time and is perfect for experiments.
  • Scripts are .py files you can save and run again.
  • print() displays output, text goes in quotes, and # starts a comment.
  • Error messages are clues. Read the last line first.

Sources checked: python.org downloads and the official Python Tutorial.

If you’d like a quick warm-up, try our Python basics practice quiz. In Lesson 2 you’ll store information in variables.

Progress is saved in this browser only.