Cohort 4Register

PART 1 · PYTHON FROM ZERO · LESSON 1

What Python is, and running your first program

FreeLesson 3 of 78

Python is a language for giving a computer step-by-step instructions in words that read almost like English. This page gets one running.

A Python program is a text file ending in .py. Python reads it from the top line to the bottom, one instruction at a time. Data engineers use it to read files, clean data, call APIs and load warehouses, because the code stays short and the libraries already exist for almost every job.

Step 1: set up once

YOUR TERMINALTERMINAL · NOT RUN
# 1. Check Python is installed (3.10 or newer)
python3 --version

# 2. Make a folder and a virtual environment for it
mkdir python_de && cd python_de
python3 -m venv .venv
source .venv/bin/activate
# on Windows: .venv\Scripts\activate

# 3. Save the code on the right as hello.py, then run it
python3 hello.py

No Python yet? Install it from python.org (tick "Add Python to PATH" on Windows). Use VS Code as your editor, or Jupyter if you like running code in small pieces.

Step 2: your first program

HELLO.PYPYTHON 3.12
# Lines starting with # are comments.
# Python ignores them; they are notes for humans.

print("Hello, data engineer!")
print("Orders today:", 15)
print(2 + 3)

Output

Hello, data engineer!
Orders today: 15
5

Three rules Python is strict about

RULE 1: INDENTATION MEANS SOMETHINGPYTHON 3.12
amount = 1198
if amount > 1000:
    print("big order")  # 4 spaces: inside the if
print("done")          # back left: after the if

Output

big order
done
RULE 2: CAPITALS MATTERPYTHON 3.12
print("Amount")
Print("Amount")        # capital P: another name

Output

Amount
NameError: name 'Print' is not defined. Did you mean: 'print'?
WordMeaning in plain English
Program / scriptA .py file with instructions
TerminalThe text window where you type commands like python3 hello.py
InterpreterThe python3 program that reads your file and runs it line by line
OutputWhatever your program prints. Every grey OUTPUT box in this book is real output
Virtual environment (.venv)A private folder of libraries for one project, so projects do not clash

Try it yourself before moving on

  1. Print your name and your city on two separate lines.
  2. Print the result of 1198 + 796 with a label in front of it.
  3. Remove the 4 spaces before print("big order") and read the error Python gives you.

Watch the free lesson

The same topic in the Free Lessons library, free with a sign-in.