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

Program entry point

A module run as a script or with python -m receives the name `__main__` for its top-level code.

Intermediate · Python 3.14; repository image, production runtime not attested
Python

Records and aggregates

Model one record with named fields and calculate an aggregate across many records.

Intermediate · Python 3.14; repository image, production runtime not attested
Python

Recursion

A recursive function solves smaller subproblems and terminates each branch at a base case.

Intermediate · Python 3.14; repository image, production runtime not attested
Python

Reductions and statistics

Reduce a finite sample to a total or a statistic suited to the question.

Intermediate · Python 3.14; repository image, production runtime not attested
Python

Regular expressions

A pattern describes text structure and fullmatch requires the entire string to match.

Intermediate · Python 3.14; repository image, production runtime not attested
Python

Scope and lifetime

Scope determines where a name can be resolved, while references can keep an object alive beyond a function call.

Basic · Python 3.14; repository image, production runtime not attested
Python

Trust boundaries and input validation

At an input boundary, bound the size before parsing and validate the resulting value against application rules.

Intermediate · Python 3.14; repository image, production runtime not attested
Python

Sorting and comparison

Sort records by a key that is computed once per input element.

Intermediate · Python 3.14; repository image, production runtime not attested
Python

Unicode text and bytes

A str is an immutable sequence of Unicode code points, while bytes hold encoded octets.

Intermediate · Python 3.14; repository image, production runtime not attested
Python

Testing and assertions

A test compares observed behavior to an expectation, including values on either side of a boundary.

Intermediate · Python 3.14; repository image, production runtime not attested
Python

Dates, instants and durations

Represent calendar dates separately from instants with a UTC offset and durations with timedelta.

Intermediate · Python 3.14; repository image, production runtime not attested
Python

Type conversion

A type constructor converts a value according to its own rules and raises an exception for unsupported input.

Intermediate · Python 3.14; repository image, production runtime not attested
Python

Type system

Every object has a type that determines its operations, while a parameter annotation imposes no automatic runtime type check.

Basic · Python 3.14; repository image, production runtime not attested
Python

Type annotations and protocols

An annotation can describe the interface a static checker expects without requiring a shared base class.

Intermediate · Python 3.14; repository image, production runtime not attested
Python

Variables and name binding

Assignment to a name binds it to the right-hand object without copying that object.

Basic · Python 3.14; repository image, production runtime not attested
Python

Ellipsis / ...

The three-dot literal denotes the singleton Ellipsis, which can be recognized by identity.

Intermediate · Python 3.14; repository image, production runtime not attested
Python

NotImplemented

NotImplemented is a singleton that an operator method can return to decline an operand pairing.

Intermediate · Python 3.14; repository image, production runtime not attested
Python

Attach and detach logging handlers with addHandler

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.

Advanced · Python 3.12
Python

The `*args` parameter: collecting positional arguments

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.

Advanced · Python 3.12
Python

Testing exceptions with assertRaises

Use `unittest.TestCase.assertRaises` in callable form or in a `with` block to check that an operation raises the expected exception.

Intermediate · Python 3.12
Python

Appending to the right of a `deque`

`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.

Advanced · Python 3.12