Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Knowledge base

Knowledge base

Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.

Entries: 5788

Python

ExitStack.close(): explicit LIFO cleanup

Register context managers at runtime, then call `stack.close()` to release their resources in reverse registration order before the enclosing `with` block ends.

Advanced · Python 3.12
Python

Attach a UTC offset with datetime.replace()

Attach a known fixed UTC offset without changing the calendar date or clock reading, then format the result as either a custom string or an ISO 8601 string.

Intermediate · Python 3.12
Python

Dictionary unpacking: `{**a, **b}`

Merge defaults and overrides into a new dictionary. When both inputs contain the same key, the value from the right wins.

Intermediate · Python 3.12
Python

The `...` literal in an abstract method body

In Python 3.12, `...` denotes the `Ellipsis` object. A bare `...` can signal an omitted implementation, but `@abstractmethod`, not `...`, marks the method as abstract.

Advanced · Python 3.12
Python

Forward-reference annotation

In Python 3.12, a quoted type annotation can refer to a name that becomes available only after the function is defined.

Basic · Python 3.12
Python

Forward references in type annotations

In Python 3.12, quote a type name that is not yet available when a method is defined, then resolve the reference later if you need the class object.

Advanced · Python 3.12
Python

Function docstrings, `__doc__`, and `__name__`

Read a function's documentation without calling it, and preserve its name and docstring across decoration so audit logs and reports describe the intended function.

Advanced · Python 3.12
Python

`io.StringIO.read`: reading text from memory

Read from the current position in a `StringIO` text stream, and distinguish that operation from retrieving the entire buffer with `getvalue()`.

Intermediate · Python 3.12
Python

Attach a logging handler and stop propagation

Use `addHandler()` to attach a handler to a specific logger, and set `propagate = False` to keep its records from reaching handlers on ancestor loggers, including the root logger.

Intermediate · Python 3.12