🎯 Learning Objectives
- Understand what Python is and why it's worth learning
- Install Python 3 on your operating system and verify it works
- Use the Python REPL (interactive shell) for quick experiments
- Write, save, and run your first
.pyscript - Use
print()and write comments in Python
What is Python?
Python is a general-purpose, high-level, interpreted programming language created by Guido van Rossum and first released in 1991. It is consistently ranked as one of the world's most popular languages — used in web development, data science, machine learning, automation, scientific computing, and far more.
"Interpreted" means Python reads and runs your source code line by line at runtime, rather than compiling it to machine code ahead of time. This makes development fast: change a line, run again, see the result immediately.
The Zen of Python
Python has an official set of guiding principles. Run import this in the
REPL to see all 19 aphorisms. Here are the most important ones to remember as a beginner:
Installing Python
Download Python 3.11 or later (3.12 recommended as of 2024). Python 2 reached end-of-life in 2020 — always use Python 3.
Option 1 — Official installer (recommended)
Go to python.org/downloads, click the yellow "Download Python 3.x.x" button. Run the installer and check "Add python.exe to PATH" before clicking Install Now.
Option 2 — Microsoft Store
Search "Python 3.12" in the Microsoft Store and click Install. PATH is set automatically.
Verify
python --version
# Python 3.12.0
Option 1 — Homebrew (recommended)
brew install python3
Option 2 — Official installer
Download the macOS package from python.org/downloads and run the .pkg installer.
Verify
python3 --version
# Python 3.12.0
Ubuntu / Debian
sudo apt update
sudo apt install python3 python3-pip
Fedora / RHEL
sudo dnf install python3
Verify
python3 --version
# Python 3.12.0
python3. On Windows it depends on how you
installed Python — try python first, then python3 if that fails.
The Python REPL
The REPL (Read-Eval-Print Loop) is an interactive Python shell built into the interpreter. You type a statement, Python reads it, evaluates it, prints the result, and loops back for the next input.
Start it from your terminal:
python3
You'll see the >>> prompt. Try these:
4
>>> "hello" + " world"
'hello world'
>>> type(42)
<class 'int'>
>>> 10 ** 3
1000
>>> exit() # or Ctrl+D / Ctrl+Z
Your First Script
While the REPL is great for experiments, real programs live in .py files. Follow these steps to create and run your first script:
- Open any text editor (VS Code, Notepad, nano — anything).
- Create a new file called
hello.py. - Type the code below and save the file.
- Open your terminal, navigate to the folder containing
hello.py, and run it.
# My first Python program
print("Hello, World!")
print("Python is fun.")
print(1 + 1)
hello.py
python3 hello.py
# Hello, World!
# Python is fun.
# 2
Python executes the file from top to bottom, one statement at a time. Every line you see above runs in order — line 1 first, then line 2, then line 3.
Understanding print()
print() is a built-in function — one of many tools Python
provides out of the box. It writes its argument(s) to standard output (your terminal).
print("Hello") # prints a string
print(42) # prints a number
print(3.14) # prints a float
print("Sum:", 10 + 5) # prints label + result → Sum: 15
print("a", "b", "c") # multiple values → a b c
print("line1\nline2") # \n is a newline character
print_examples.py
print(...). The value(s) inside
the parentheses are called arguments. We'll build our own functions in Lesson 11.
Comments
A comment is text in your code that Python completely ignores.
Anything after a # character on a line is a comment.
# This entire line is a comment — Python skips it
print("visible") # This part is a comment; print() still runs
# Comments explain WHY your code does something,
# not just what it does. Good comments save future-you.
# TODO: add error handling here
# FIXME: this formula is wrong for negative inputs
comments.py
# lines, or a triple-quoted string (but those aren't true comments —
we'll cover them properly in Lesson 03).
Code Style: PEP 8
PEP 8 is Python's official style guide. You don't need to memorise it now, but three rules matter from day one:
- Use 4 spaces per indentation level (not tabs).
- Keep lines to 79 characters or fewer.
- Put a space around operators:
x = 1 + 2, notx=1+2.
Most editors (VS Code, PyCharm) will auto-format Python for you. The tool
black can reformat an entire project automatically — we'll use it later.
Primary sources: Python Docs — Using the Interpreter · PEP 8 — Style Guide
Ask your AI tutor! Stuck on installation? Not sure what
PATH means? Confused about the difference between python
and python3? Ask — setup issues are the most common beginner blocker
and there's no shame in needing help here.
💻 Exercises
Create a file called me.py. Using print(), output three
lines: your name, your favourite number multiplied by 7, and the message
"I am learning Python.". Run it in your terminal.
Show solution
print("Alice")
print(6 * 7) # 42
print("I am learning Python.")
Open the Python REPL and evaluate at least six expressions. Try: arithmetic
(17 % 3), string repetition ("ha" * 3),
and type() on an integer, a string, and a float.
Note what each one returns.
Show solution
>>> 17 % 3 # modulo (remainder)
2
>>> "ha" * 3
'hahaha'
>>> type(42)
<class 'int'>
>>> type("hello")
<class 'str'>
>>> type(3.14)
<class 'float'>
>>> 2 ** 10 # 2 to the power 10
1024
Start the REPL and type import this. Read all 19 aphorisms.
Pick the one that resonates most with you and write a short comment in a
zen.py file explaining why.
Show solution
# "Readability counts."
#
# I chose this one because the whole point of code is
# communication — first with the computer, then with
# other humans (including future-me). If it's hard to
# read, it's hard to debug and hard to improve.
import this # prints the full Zen of Python