Programming Tutorials
Standalone programming tutorials for solving one specific problem at a time. Each guide starts with the exact error message, failing behavior, or design constraint, gives you a minimal reproducible script or query, and walks through the fix with real output.
Pick a language below or filter by topic and difficulty when you need a quick, practical reference you can test locally and apply right away.
A closure remembers variables from the function that created it.
Don't guess which part is slow. Run cProfile, read cumtime and tottime the right way, fix the one line that matters, and measure again.
A for loop calls iter() once and next() until StopIteration.
If a class mostly holds data, @dataclass writes __init__, a readable printout and equality for you.
ModuleNotFoundError has a handful of causes: the wrong Python, an inactive virtual environment, the wrong folder, or a file that shadows a module.
Defaults make functions easier to call and keywords make calls easier to read. A list as a default value is created once and shared by every call. Here's why, and the one-line fix.
An if/elif chain stops at the first true condition. Put the widest one first and the others never run, with no error.
Importing a file runs it. if __name__ == "__main__" keeps a file's script part from running when another file imports it.
Python is probably installed. Your terminal just can't find it.
/, //, % and round() each do exactly what they say, and that's not always what school math taught you.
print() is for the output a person asked for. logging is for messages about the program: levels you can turn down, a file with times, and tracebacks for errors.
Start mypy with its defaults, fix what it finds, turn on check_untyped_defs, then make one module at a time strict.