TodayTools

Python flashcards

Readable code for scripts, web apps, data and AI.

Donate
Beginner friendly, starts from zero
Section
How to study
0
PythonStart from zero · 1 of 12

What is Python, in one plain sentence?

Python is a programming language: a way to write instructions a computer follows, using words close to plain English.

Instructions a computer can read and a person can too.

All topics

Python at a glance

Python is a programming language for writing instructions a computer follows, in words close to plain English.

Like a recipe: steps in order, ingredients in labelled boxes, and some steps repeated for each item.

Words you will meet

Interpreter
The program that reads your code and runs each line
Variable
A name label on a value, like age
Type
What kind a value is: number, text, true or false
List
An ordered row of values you can change
Dict
Pairs of keys and values, like a phone book
Function
A named set of steps you can reuse
Loop
Steps repeated for each item
Block
Indented lines that belong together

The steps

  1. 1. Start from zero (12 cards): What Python is, the words you need, and your first line of code.
  2. 2. Core basics (17 cards): How Python runs, names and values, types, lists, dicts, loops and functions.
  3. 3. Next steps (18 cards): Errors, files, classes, packages, environments, typing and the standard library.
  4. 4. Go deeper (18 cards): Generators, decorators, async, concurrency, the GIL, typing and performance.
All 12 cards in Start from zero
What is Python, in one plain sentence?
Python is a programming language: a way to write instructions a computer follows, using words close to plain English.
What problem does Python solve for everyday people?
Boring repeated work, like copying 500 marks into a sheet or renaming 300 photos by hand. A short Python script does it in seconds, and it does not get tired or make typing mistakes.
Where might you already meet Python in daily life?
Behind many websites and AI chat tools, in banks' reports, in science labs, and in small scripts at offices that tidy files or send daily emails.
What everyday thing is a Python program most like?
A recipe. Steps run in order, ingredients sit in labelled boxes, and lines like 'for each egg, crack it' repeat a step many times.
What do 'code', 'program', 'run' and 'interpreter' mean?
Code is the text you write; a program is a file of it, like report.py. To run it, the Python interpreter, the program that reads your code, does each line from top to bottom.
What are a 'value', a 'type' and a 'variable'?
A value is a piece of data. Its type says what kind: int whole number, float decimal, str text in quotes, bool True or False. A variable is a name label on a value: age = 12.
What are a 'list', a 'dict', a 'tuple' and a 'set'?
Ways to hold many values. A list is an ordered row, ["tea", "rice"]. A dict pairs keys with values, {"rice": 40}. A tuple is a fixed list, (13.08, 80.27). A set keeps no duplicates, {101, 102}.
What do 'function', 'return' and 'method' mean?
A function is a named set of steps you can reuse, like print. It may return, that is hand back, a result. A method is a function that belongs to a value, like name.upper().
What are a 'loop', a 'block' and an 'error'?
A loop like for repeats steps for each item. The indented lines under it form a block, and Python uses that indent to know what is inside. An error, also called an exception, is Python stopping to say something went wrong.
What do you need before starting this topic?
A computer with Python 3 from python.org, a terminal (a text window for typing commands) and a text editor. Later you will use pip, the tool that installs packages: ready-made code others shared.
Your first tiny win: what does this print?
The first line stores the text in a variable called name. print shows the joined text on screen, so you see a greeting with that name.
What will you be able to do after this topic?
Write small scripts that work with text, numbers and lists, read files, handle bad input without crashing, and split work into clean functions.
Python cheatsheet

Strings and formatting

  • s.strip() / s.removeprefix("v") Trim spaces / drop a known prefix
  • s.split(",", maxsplit=1) Split, at most once
  • ", ".join(names) Join items into one string
  • f"{amount:,.2f}" 1,234.50 style number
  • f"{ratio:.1%}" Percentage, one decimal
  • f"{user_id=}" Debug print: user_id=812
  • f"{name!r:>12}" repr, right aligned in 12
  • s.casefold() == t.casefold() Case-insensitive compare

Collections

  • d.get(k, default) Read without KeyError
  • d.setdefault(k, []).append(x) Group without checks
  • a | b / d |= other Merge dicts (3.9+)
  • Counter(xs).most_common(3) Top 3 by count
  • defaultdict(list) Auto empty list per key
  • deque(maxlen=100) Fast queue, keeps last 100
  • dict.fromkeys(emails) Dedupe, keep order
  • sorted(xs, key=itemgetter(1), reverse=True) Sort by field, descending
  • bisect.insort(xs, x) Insert keeping a list sorted

Iteration

  • enumerate(xs, start=1) Index plus item
  • zip(a, b, strict=True) Pairs; error on length mismatch
  • itertools.batched(xs, 100) Chunks of 100 (3.12+)
  • itertools.chain.from_iterable(lists) Flatten one level
  • itertools.groupby(sorted_xs, key) Group runs; sort first
  • itertools.pairwise(xs) Neighbours: (a,b), (b,c)
  • any(...) / all(...) Short-circuit checks
  • next(iter(xs), None) First item or None

Tooling

  • uv init / uv add httpx New project / add dependency
  • uv run pytest -q Run in the synced environment
  • uv python install 3.14 Install a Python version
  • uvx ruff check --fix . Lint and auto-fix
  • ruff format . Format code
  • pyright / mypy --strict Static type check
  • pytest -x -k invoice --lf Stop on fail, filter, rerun failures
  • python3 -X importtime app.py Find slow imports

Debug and profile

  • breakpoint() Drop into pdb here
  • python3 -m pdb -c continue app.py Debugger on crash
  • python3 -m cProfile -s cumtime app.py Where time goes
  • py-spy top --pid PID Profile a live process
  • python3 -m json.tool data.json Pretty-print JSON
  • tracemalloc.start() Track memory allocations
  • python3 -W error app.py Turn warnings into errors
Donate