Python Lists: Indexing, Methods, and Sorting
See how Python lists store ordered items, count duplicates, and change in place. Compare append, extend, remove, pop, and sorted.
5 min readUnderstand the language one decision at a time, from choosing a data type to reading an exception.
See how Python lists store ordered items, count duplicates, and change in place. Compare append, extend, remove, pop, and sorted.
5 min readUse list.pop() to take the last item or pass an index to take another. See what happens on an empty list and when to use remove or del.
3 min readCreate a one-item tuple, unpack a pair, and see why a tuple can hold a list but cannot always serve as a dictionary key.
3 min readRemove duplicates with set(), check membership with in, and compare two sets with intersection, union, and difference.
5 min readRead an optional dictionary key with dict.get(). Distinguish a missing key from None, zero, False, and an empty string.
3 min readCall len() to count dictionary entries. Learn why empty values still count and how to count items inside a nested dictionary.
3 min readLoop over a list or dictionary, pick range() or enumerate(), and see when break, continue, and else run.
5 min readUse range(1, 11) to count from 1 to 10. See how the exclusive stop and a negative step affect Python loops.
3 min readGet a count and value together in a Python loop. Start at zero or one and keep source positions when you filter items.
3 min readUse a while loop when work ends as a condition changes. Set a clear exit, bound retry attempts, and avoid infinite loops.
3 min readDefine and call a Python function, choose keyword arguments and defaults, and understand when a call returns None.
5 min readSee how a class creates instances, what self refers to, and how to give each object its own state.
5 min readSee which Python branch runs first, how to combine Boolean conditions, and how to handle boundaries, missing values, and defaults.
5 min readMatch Python values or record shapes with case. Learn what a bare name captures, where a guard runs, and how to add a fallback.
3 min readPut variables in f-strings, format decimal places and percentages, align columns, and print literal braces.
3 min readSee why 7 // 3 is 2 and -7 // 3 is -3. Compare // with /, truncation, and the remainder returned by divmod().
3 min readClean and compare Python strings with strip(), split(), join(), find(), replace(), and casefold(). See what each method returns.
4 min readSlice Python lists or strings with start, stop, and step. Read negative-step examples and see what a list slice copies.
3 min readSee which strings Python recognizes as docstrings, how help() displays them, and when a # comment belongs next to the code.
3 min readControl Python print() spacing, newlines, output files, and buffering. See why a printed value and a returned value are different.
3 min readChoose built-in Python types, convert text to numbers and flags, and understand mutability, equality, and type checks.
5 min readCatch a specific Python exception, keep success code in else, clean up with finally, and preserve the original cause with raise from.
3 min read