Python Foundations
Set up Python 3.12+ and follow a practical path from values to reusable functions.
Python is easiest to learn by running small programs, predicting their results, and changing one thing at a time. This track builds the vocabulary and habits needed for scripts, data work, web applications, and later object-oriented programming.
Target version
These lessons use Python 3.12 or newer. Most examples also work on recent older versions, but install a supported release so error messages and language features match the course.
Learning path
Work through the pages in order:
- Syntax and values — names, types, expressions, and mutability.
- Operators and conditionals — compute values and make decisions.
- Strings and built-ins — process text and use Python's standard tools.
- Lists and tuples — model ordered collections.
- Dictionaries and sets — model lookup tables and unique membership.
- Iteration — loop directly, pair data, transform it, and sort it.
- Functions — package behavior behind clear interfaces.
- Arguments and unpacking — design flexible calls and destructure values.
Install and verify Python
Download Python from python.org or use your operating
system's package manager. On Windows, enable the option that adds Python to PATH.
Open a terminal and verify the interpreter:
python --version
Python 3.12.4Some systems expose Python 3 as python3 or the Windows launcher as py:
python3 --version
py -3.12 --versionUse whichever command reports the intended version consistently.
Run Python in two ways
The interactive shell is ideal for experiments:
python
>>> 2 + 3
5
>>> exit()For programs you want to keep, create hello.py:
name = "Ada"
print(f"Hello, {name}!")Then run it:
python hello.pyPython executes a file from top to bottom. When something fails, read the final line of the traceback first: it names the exception and usually explains the immediate problem.
A useful project setup
Create a virtual environment for each project. It isolates installed packages:
python -m venv .venvActivate it on Windows PowerShell:
.\.venv\Scripts\Activate.ps1Activate it on macOS or Linux:
source .venv/bin/activateThe standard library examples in this track need no third-party packages.
How to study
For every example:
- Predict the output before running it.
- Type it rather than pasting it.
- Change inputs and observe what remains true.
- Explain the result in plain language.
- Turn the idea into a tiny program.
Choose names that state intent (total_price, not tp), keep programs small, and prefer
obvious code over clever shortcuts.
Common mistakes
- Running the wrong interpreter: compare
python --versioninside and outside your virtual environment. - Naming a file after a standard module: files such as
random.pyorjson.pycan shadow the real modules. - Typing shell commands at
>>>: leave the Python shell before running terminal commands. - Ignoring the whole traceback: the first cause may be several lines above the final error.
- Learning only by reading: syntax becomes usable only through retrieval and practice.
Practice
- Verify that Python 3.12+ is available.
- Create and activate a virtual environment.
- Write a program that stores your name and current learning goal, then prints both.
- Intentionally misspell
print, run the file, and identify the exception type and line.
LEARNING RECORD
Finish this lesson
Mark it complete when you can explain the main decision without looking.
KNOWLEDGE CHECK