Python

Python · Browse articles by tag (only tags with 5+ articles get a page).

ProgrammingIntermediateSeries 3

Python Classes and Object-Oriented Basics

Define classes, tell instance and class attributes apart, use @property, @classmethod and inheritance with super(), and implement __repr__ and __eq__ correctly.

ProgrammingIntermediateSeries 2

Command-Line Tools and Project Layout in Python

Build a CLI with argparse: positional and optional arguments, types, choices, custom validators and subcommands, then package it with src layout, pyproject.toml and correct exit codes.

ProgrammingIntermediateSeries 1

Python Comprehensions and Iteration Tools

List, dict and set comprehensions, generator expressions, and the standard library helpers — enumerate, zip, sorted, itertools — that replace most manual loops.

ProgrammingBeginnerSeries 2

Python Conditionals and Loops

How truthiness works in Python, when to use for versus while, the rarely used loop else clause, and the iteration mistakes that produce wrong results.

ProgrammingIntermediateSeries 3

Cleaning CSV Data and Writing a JSON Report

A complete, runnable script: read a messy CSV with csv.DictReader, validate and convert each row, count skipped rows by reason, aggregate with collections, and write a JSON report.

ProgrammingIntermediateSeries 4

Python dataclasses and Type Hints

Annotate your code so editors and mypy catch mistakes before runtime, then let @dataclass generate __init__, __repr__ and __eq__ — with default_factory, frozen and slots.

ProgrammingBeginnerSeries 8

Python Exceptions and Custom Errors

How try/except/else/finally actually runs, which exceptions to catch, keeping context with raise from, designing custom error hierarchies, and the anti-patterns that hide bugs.

ProgrammingBeginnerSeries 7

Reading and Writing Files in Python

Open files safely with with, stream large files line by line, build paths with pathlib, and handle JSON, CSV, and encodings without the usual surprises.

ProgrammingBeginnerSeries 6

Python Functions and Argument Passing

Define functions, mix positional and keyword arguments, avoid the mutable default trap, collect extra arguments with *args and **kwargs, and understand scope rules.

ProgrammingIntermediateSeries 5

Python Iterators and Generators

Separate iterables from iterators, trace exactly how yield suspends a function, stream a large file through a generator pipeline, and know when yield from, send and close are worth the complexity.

ProgrammingBeginnerSeries 4

Python Lists and Dictionaries in Practice

The list and dict operations you reach for daily: slicing, iteration, shallow versus deep copies, get versus indexing, and grouping with setdefault.

ProgrammingIntermediateSeries 2

Python Modules, Packages and Virtual Environments

How imports resolve, absolute versus relative imports, the __main__ guard, and isolating dependencies per project with venv, pip and pyproject.toml.

ProgrammingIntermediateSeries 7

Regular Expressions in Python

How search, match, findall and sub actually differ, the metacharacters you need, greedy versus lazy quantifiers, named groups, compile flags, and the failure modes that make regexes fragile.

ProgrammingIntermediateSeries 6

Python Standard Library Essentials: datetime, collections and json

The standard library modules worth knowing by heart: datetime arithmetic and time zones, Counter, defaultdict and deque, json round-trips, plus os.getenv, subprocess and secrets.

ProgrammingBeginnerSeries 3

Python Strings, Slicing and Formatting

Create and inspect strings, use the methods you actually reach for, format output with f-strings, and keep str and bytes straight at the encoding boundary.

ProgrammingIntermediateSeries 1

Testing Python with pytest

Write your first pytest test, then use plain asserts, pytest.raises, parametrize, fixtures and tmp_path — plus how to organise tests and the anti-patterns that make a suite untrustworthy.

ProgrammingBeginnerSeries 5

Python Tuples, Sets and Immutability

When a tuple beats a list, how packing and unpacking work, what immutability actually prevents, and why sets give O(1) membership tests.

ProgrammingBeginnerSeries 1

Python Variables and Data Types

How Python variable binding actually works, the built-in types you use daily, and why mutable vs immutable changes how bugs show up.