Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

Knowledge base — Python

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

Entries: 583

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
Python

Get a child logger with Logger.getChild

Look up a logger relative to its parent’s name and send its records to the parent’s handler without copying that handler onto the child.

Intermediate · Python 3.12
Python

Logger handlers: inspect, detach, and attach

In Python 3.12, `logger.handlers` shows only the handlers attached directly to a logger. Read the list to inspect it; use `addHandler()` and `removeHandler()` to change it.

Advanced · Python 3.12
Python

Set a named logger’s threshold with setLevel()

Set a named logger to `logging.INFO` to drop `DEBUG` while allowing `INFO` and higher levels past the logger’s threshold. The handler still controls what reaches its output.

Intermediate · Python 3.12
Python

`object.__next__`: advancing an iterator

`__next__` returns one item and advances the iterator. Once the iterator is exhausted, the method raises `StopIteration` on every further call.

Advanced · Python 3.12
Python

Raw string literal `r'...'` in Python

Use the `r` prefix to keep backslashes in a string value. This is useful for regular expressions: Python preserves the backslashes, and `re` interprets them.

Intermediate · Python 3.12
Python

Python raw string literals: the r prefix

The `r` prefix preserves backslashes in a `str` literal. This makes regular-expression patterns easier to read without changing how `re` interprets them.

Advanced · Python 3.12
Python

re.Pattern.fullmatch: Match the entire string

Use this compiled regular expression method to check whether the pattern matches the entire string or the entire range selected by `pos` and `endpos`.

Intermediate · Python 3.12
Python

Set difference: the `-` operator

The `-` operator builds a new set from elements found in the left set but not the right one. With integers, the same operator performs arithmetic subtraction.

Basic · Python 3.12
Python

Set symmetric difference (`^`)

Use `^` to keep elements that belong to exactly one of two sets. The same operator performs bitwise XOR when both operands are integers.

Basic · Python 3.12
Python

Set union with `|`

Use `|` to combine sets without changing either operand. With two integers, the same operator performs bitwise OR instead.

Basic · Python 3.12
Python

Set intersection with `&`

Use `&` to find the elements two sets share. The same operator performs bitwise AND when both operands are integers.

Basic · Python 3.12
Python

strftime: format a datetime with a UTC offset

Attach a known fixed UTC offset without changing the clock time, then display the same datetime using a custom format and an ISO 8601 representation.

Intermediate · Python 3.12
Python

TestResult: a four-line unittest report

Run a test suite and use the returned `TestResult` to report how many tests started, how many failures and errors were recorded, and whether the run was successful.

Intermediate · Python 3.12