Iterables and iterators
An iterable can produce an iterator; an iterator returns successive values with next().
The question library
Explore practical questions, clear explanations, and code examples across developer technologies.
Showing 2929–2940 of 3610 questions
An iterable can produce an iterator; an iterator returns successive values with next().
A generator yields values lazily and preserves its state between requests.
A shallow copy duplicates the outer container but shares nested objects; deep copy recursively copies nested structures.
try/except handles expected errors; else and finally support success and cleanup paths.
Raise an exception when input or state violates a function's contract.
A context manager manages setup and cleanup, commonly with the with statement.
Use with for cleanup and specify encoding for text files.
pathlib provides cross-platform path operations using Path objects.
A module is commonly a Python file; a package organizes related modules under a namespace.
The main guard runs code only when a module is executed directly, not when imported.
A decorator wraps or transforms a function or class to add behavior.
dataclasses generate common methods for classes mainly used to store data.