Kodokon kodokon.com

Install Python and write your first program

You install Python, discover the REPL, and print your first message with print.

8 min · 3 questions

Open this lesson in Kodokon

Welcome! A program is a list of instructions that the computer runs one after another. To write these instructions, we use a programming language: a set of words and rules that the computer understands. Python is one of these languages, known for its readability: it's the ideal choice to get started. First step: head to the official website python.org, section "Downloads", and install the latest version. On Windows, tick the Add Python to PATH box: it makes Python accessible from the terminal, a window in which you type commands with the keyboard (search for "Terminal" or "PowerShell" in your menu).

BASH
python --version
Type this command in the terminal: if a version number appears, Python is properly installed.

Python offers an interactive mode called the REPL (Read-Eval-Print Loop). It reads what you type, runs it immediately, and displays the result. To open it, type python in the terminal. The three chevrons >>> then prompt you to write code. Try a simple calculation, then quit with exit().

PYTHON
2 + 3
7 * 6
Type this in the REPL, one line at a time: each result appears right away (5, then 42).

The REPL is perfect for testing, but a real program is written in a file. Open a text editor (VS Code, for example, which is free) and discover print. It's a function: a ready-made instruction that you call by its name, followed by parentheses. print displays on screen whatever you give it inside the parentheses. The text must be placed inside quotation marks: this is called a string.

PYTHON
print("Hello, world!")
print("I'm programming in Python.")
Your first program: two calls to the print function.

Knowledge check

Make sure you remember the key points of this lesson.

  1. What does the print function do?
    • It displays text on screen
    • It prints the page on paper
    • It installs Python
    • It closes the program
  2. What is Python's REPL?
    • A file that contains a Python program
    • An interactive mode that reads, runs, and immediately displays each instruction
    • A piece of software for downloading Python
  3. Which command runs the hello.py file from the terminal?
    • python hello.py
    • run hello.py
    • print(hello.py)
    • open hello.py