Program entry point
A module run as a script or with python -m receives the name `__main__` for its top-level code.
CKTIS / Python
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
A module run as a script or with python -m receives the name `__main__` for its top-level code.
Model one record with named fields and calculate an aggregate across many records.
A recursive function solves smaller subproblems and terminates each branch at a base case.
Reduce a finite sample to a total or a statistic suited to the question.
A pattern describes text structure and fullmatch requires the entire string to match.
Scope determines where a name can be resolved, while references can keep an object alive beyond a function call.
At an input boundary, bound the size before parsing and validate the resulting value against application rules.
Sort records by a key that is computed once per input element.
A str is an immutable sequence of Unicode code points, while bytes hold encoded octets.
A test compares observed behavior to an expectation, including values on either side of a boundary.
Represent calendar dates separately from instants with a UTC offset and durations with timedelta.
A type constructor converts a value according to its own rules and raises an exception for unsupported input.
Every object has a type that determines its operations, while a parameter annotation imposes no automatic runtime type check.
An annotation can describe the interface a static checker expects without requiring a shared base class.
Assignment to a name binds it to the right-hand object without copying that object.
The three-dot literal denotes the singleton Ellipsis, which can be recognized by identity.
NotImplemented is a singleton that an operator method can return to decline an operand pairing.
Inspect the handlers attached directly to a logger, attach a configured handler with `addHandler()`, and empty the list through `removeHandler()` rather than editing it directly.
In a function definition, `*args` collects extra positional arguments and `**kwargs` collects extra keyword arguments. In a call, the same star syntax unpacks values instead.
In a function definition, `*args` collects leftover positional arguments into a tuple. In the call `fn(*args)`, the star does the reverse: it passes the tuple’s items as separate positional arguments.
Use `assertEqual` to compare actual and expected values, prepare test data with `setUp`, and cover multiple inputs and exceptions in `unittest`.
Use `unittest.TestCase.assertRaises` in callable form or in a `with` block to check that an operation raises the expected exception.
Request cancellation, wait for the task to finish, then report its name and whether it was actually cancelled.
`collections.deque.append` adds one item to the right end of a double-ended queue. In this sliding-window example, the monotonic queue stores indices rather than the values themselves.