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

The `X | None` type union

`X | None` describes a value of type `X` or the value `None`. In `-> str | None`, it describes a function's return value, not a default.

Advanced · Python 3.12
Python

Variadic positional parameters: `*args`

In a function definition, `*args` collects extra positional arguments into a tuple. In a call, `*` unpacks an iterable into positional arguments.

Advanced · Python 3.12
Python

Variadic parameters `*args` and `**kwargs`

In Python 3.12, `*args` collects extra positional arguments into a tuple and `**kwargs` collects unmatched keyword arguments into a dictionary. At the call site, the same symbols unpack arguments.

Intermediate · Python 3.12
Python

Variadic positional parameter `*items`

In a function definition, `*items` collects leftover positional arguments into a tuple. At a call site, `*values` does the reverse: it passes the elements of an iterable as separate positional arguments.

Advanced · Python 3.12
Python

Write, read, and retrieve text with io.StringIO

Use `write()` to build text in memory one piece at a time, `read()` to consume text from the current position, and `getvalue()` to retrieve the whole buffer without rewinding.

Intermediate · Python 3.12
Python

AssertionError — a failed assertion

AssertionError is a built-in exception raised when an assert statement's condition is false. Assertions check internal program assumptions, not mandatory input validation: optimization can remove them.

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

Exception — base class for ordinary exceptions

Exception is Python’s built-in base class for ordinary exceptions. It lets you define custom error types and catch them together, but does not cover every descendant of BaseException.

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

IndexError — sequence index out of range

IndexError is a built-in exception raised when an attempt to access a sequence element uses an out-of-range index. Learn valid index bounds, the difference between indexing and slicing, and how to catch this exception.

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

KeyError — missing mapping key

KeyError means that a requested key was not found in a mapping, such as a dict. Learn the difference between square-bracket lookup and get(), and handle missing keys without hiding unrelated errors.

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

NameError — referencing an undefined name

NameError means Python could not find a referenced name in the available scopes. Check spelling, assignment order, and imports. Distinguish NameError from AttributeError. UnboundLocalError is a subclass of NameError.

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

StopIteration — iterator exhaustion

StopIteration signals iterator exhaustion during next(). Its value attribute can carry a generator's return value. Ending a generator with return is different from allowing an explicitly raised StopIteration to escape its code.

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

TimeoutError / asyncio.TimeoutError — exceeding a time limit

TimeoutError signals that an operation exceeded its time limit. In Python 3.14, asyncio.TimeoutError is a deprecated alias of the same class, not a separate exception. Catch TimeoutError and distinguish a timeout from ordinary task cancellation.

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

TypeError — an operation on an object of an inappropriate type

TypeError means that an operation or function received an object of an inappropriate type. Learn how it differs from ValueError and how to handle it without hiding the underlying problem.

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

UnboundLocalError — reading an unbound local variable

UnboundLocalError occurs when a function reads a local variable that has no value bound to it at that point. It is a subclass of NameError; a common cause is an assignment that shadows a variable from an outer scope.

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

ValueError — an inappropriate argument value

ValueError indicates that an argument has the correct type but an unacceptable value. Learn how it differs from TypeError and how to raise and catch it.

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

ZeroDivisionError — division by zero

ZeroDivisionError is a built-in exception raised when division or a remainder operation uses a zero divisor. Handle it with except ZeroDivisionError when the program can respond meaningfully to that case.

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

abs()

Computes an absolute value or the magnitude of a complex number.

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

aiter()

Obtains the asynchronous iterator used to consume an asynchronous iterable.

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

all()

Tests successive elements for truth and stops at the first falsy item.

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