Python
Python Quiz Exercises
Test your Python knowledge with focused quiz exercises.
Interactive exercises that help you practice, check your understanding, and find what to revisit.
Start here
Test your knowledge: Python Variables and Values
A short assessment covering assignment as binding, updating in place, and f-string interpolation.
Explore the collection
Exercises
Browse the complete collection and choose the resource that matches what you want to practice or understand.
-
ExercisesBeginner
Test your knowledge: Python Variables and Values
A short assessment covering assignment as binding, updating in place, and f-string interpolation.
~3 min read Start exercise -
ExercisesCore
Quick Check: Python Objects, Values, Types, and Identity
Check your understanding of objects, identity, equality, mutability, and hashability.
~5 min read Start exercise -
Exercises
Quick Check: Python None
Check your understanding of None, NoneType, function results, identity checks, and false values.
~5 min read Start exercise -
ExercisesBeginner
Test your knowledge: Python Numbers
Check division, unbounded integers, money-safe counting, and the real and imaginary parts of complex numbers.
~4 min read Start exercise -
ExercisesBeginner
Test your knowledge: Python Strings
A short assessment covering f-strings, slicing from either end, immutability, and join.
~3 min read Start exercise -
ExercisesBeginner
Test your knowledge: Python Booleans and Conditionals
Assess comparisons, truthiness, short-circuit behavior, operand-returning Boolean operators, and conditional branches.
~3 min read Start exercise -
ExercisesBeginner
Test your knowledge: Python Lists
A short assessment covering in-place mutation, aliasing, honest copies, and queue moves.
~3 min read Start exercise -
ExercisesBeginner
Test your knowledge: Python Dictionaries
A short assessment covering get versus brackets, items(), what in asks, and insertion order.
~3 min read Start exercise -
ExercisesBeginner
Test your knowledge: Python Loops
A short assessment covering for versus while, the exits, and numbering with enumerate.
~3 min read Start exercise -
ExercisesBeginner
Test your knowledge: Python Functions
A short assessment covering None returns, mutable defaults, scope, and keyword arguments.
~3 min read Start exercise -
ExercisesBeginner
Test your knowledge: Python range
A short assessment covering range arguments, stop exclusion, negative steps, sequence behavior, and membership.
~3 min read Start exercise -
ExercisesBeginner
Test your knowledge: Python zip
A short assessment covering parallel iteration, shortest-input behavior, strict length checking, edge cases, and unzipping.
~3 min read Start exercise -
ExercisesBeginner
Test your knowledge: Python Iterable Unpacking
Check your understanding of assignment-side iterable unpacking, starred targets, nested targets, and value swapping.
~3 min read Start exercise -
ExercisesBeginner
Test your knowledge: Python map and filter
Check your understanding of map transformation, filter selection, lazy iterator results, and multiple inputs.
~3 min read Start exercise -
ExercisesBeginner
Test your knowledge: Python Sorting with sorted()
Check your understanding of sorted(), key functions, reverse ordering, stable sorting, and list.sort().
~3 min read Start exercise -
Exercises
Python aggregation built-ins: Quick Check
Check your understanding of all(), any(), min(), max(), and sum().
~5 min read Start exercise -
Exercises
Python numeric built-ins: Quick Check
Check your understanding of abs(), divmod(), and pow().
~5 min read Start exercise -
Exercises
Python Recursion: Quick Check
Check your understanding of recursive calls, stopping conditions, returned values, local state, and recursion depth.
~5 min read Start exercise -
ExercisesIntermediate
Test your knowledge: Python Format Specifications
Check your understanding of format(), width, alignment, fill, precision, and conversion versus formatting.
~3 min read Start exercise -
Exercises
Quick Check: Python Coroutines and async/await
Check your understanding of coroutine functions, coroutine objects, await, and top-level coroutine execution.
~5 min read Start exercise -
ExercisesIntermediate
Test your knowledge: Python Asynchronous Iteration
Check async for, asynchronous iterator protocols, aiter(), anext(), and StopAsyncIteration.
~4 min read Start exercise -
ExercisesIntermediate
Test your knowledge: Python Asynchronous Generators
Check asynchronous generator creation, lazy execution, suspension, completion, delegation limits, and deterministic cleanup after early exit with contextlib.aclosing().
~4 min read Start exercise -
Exercises
Quick Check: Python Asynchronous Context Managers
Check your understanding of async with, __aenter__(), __aexit__(), awaiting, cleanup, exception handling, and protocol boundaries.
~5 min read Start exercise -
ExercisesIntermediate
Test your knowledge: Python Enumerations
Check enum members, names and values, lookup, iteration order, and duplicate-value protection.
~4 min read Start exercise -
ExercisesIntermediate
Test your knowledge: Python Copying Objects
Check aliasing, shallow copy, deep copy, recursive references, and copy.replace().
~5 min read Start exercise -
ExercisesIntermediate
Test your knowledge: Python Double-Ended Queues
Check deque end operations, FIFO queues, bounded histories, list trade-offs, and rotation.
~5 min read Start exercise -
ExercisesBeginner
Test your knowledge: Python Modules and Imports
Check your understanding of modules, import forms, namespaces, __name__, and python -m.
~3 min read Start exercise -
ExercisesBeginner
Test your knowledge: Python Tuples and Sets
A short assessment covering tuple construction, unpacking, set uniqueness, set operations, and frozenset.
~3 min read Start exercise -
ExercisesIntermediate
Quick Check: Python __init_subclass__ and Class Creation Hooks
Check your understanding of subclass creation hooks and cooperative class customization.
~4 min read Start exercise -
Exercises
Quick Check: Python __new__ and Object Creation
Check your understanding of __new__(), __init__(), immutable object creation, subclass-aware construction, and returned-object behavior.
~5 min read Start exercise -
ExercisesAdvanced
Quick Check: Python __slots__ and Instance Storage
Check your understanding of Python __slots__, instance dictionaries, reassignment, and inheritance.
~3 min read Start exercise -
Exercises
Quick Check: Python Annotations
Check annotated assignment syntax, function-local behavior, Python 3.14 deferred evaluation, and safe interpretation of runtime annotation formats.
~5 min read Start exercise -
Exercises
Quick Check: Python Argument Unpacking
Check your understanding of positional and keyword argument unpacking with * and ** in function calls.
~5 min read Start exercise -
Exercises
Quick Check: Python Assert Statements
Check your understanding of assert conditions, AssertionError, assertion messages, intended use, and optimization.
~5 min read Start exercise -
ExercisesCore
Quick Check: Python Assignment Expressions
Check your understanding of :=, captured values, scope, syntax restrictions, and when ordinary assignment is clearer.
~5 min read Start exercise -
ExercisesCore
Quick Check: Python Augmented Assignment
Check your understanding of augmented-assignment operators, target evaluation, and mutable versus immutable values.
~5 min read Start exercise -
ExercisesCore
Quick Check: Python Bytes and Bytearray
Check your understanding of immutable bytes, mutable bytearray, indexing, slicing, and text-to-binary conversion.
~5 min read Start exercise -
ExercisesAdvanced
Quick Check: Python Callable Objects and __call__
Check your understanding of callable instances, __call__, state, and call behavior.
~5 min read Start exercise -
Exercises
Quick Check: Python Class Methods and Static Methods
Check your understanding of instance, class, and static methods.
~5 min read Start exercise -
ExercisesAdvanced
Quick Check: Python Class Subscription and __class_getitem__
Check your understanding of class subscription, __class_getitem__, GenericAlias, and the boundary with instance subscription.
~5 min read Start exercise -
Exercises
Quick Check: Python Classes and Objects
Check your understanding of classes, instances, methods, attributes, and inheritance.
~5 min read Start exercise -
Exercises
Quick Check: Python Conditional Expressions
Check your understanding of conditional-expression syntax, values, evaluation, and the boundary between expressions and if statements.
~5 min read Start exercise -
Exercises
Quick Check: Python CSV
Check your understanding of CSV readers, writers, dictionary rows, newline handling, and field types.
~5 min read Start exercise -
ExercisesAdvanced
Quick Check: Python Custom Attribute Access
Check your understanding of Python attribute-access hooks and their boundaries.
~4 min read Start exercise -
ExercisesAdvanced
Quick Check: Python Custom isinstance() and issubclass() Checks
Check your understanding of __instancecheck__(), __subclasscheck__(), metaclass lookup, and virtual relationships.
~5 min read Start exercise -
ExercisesAdvanced
Quick Check: Python Custom Subscription and Container Behavior
Check subscription hooks, slicing, assignment, deletion, reverse iteration, and the read-only Mapping abstract base class.
~7 min read Start exercise -
Exercises
Quick Check: Python Decorators
Check your understanding of function and class decorator transformations, wrappers, metadata preservation, factories, and application order.
~6 min read Start exercise -
Exercises
Quick Check: Python del Statements
Check your understanding of del targets, name bindings, slices, attributes, and deletion errors.
~5 min read Start exercise -
ExercisesAdvanced
Quick Check: Python Descriptors and __set_name__
Check your understanding of descriptor lookup, binding, precedence, and class-created descriptor names.
~5 min read Start exercise -
Exercises
Quick Check: Python Exception Groups and except*
Check your understanding of ExceptionGroup and except* handling.
~5 min read Start exercise -
Exercises
Quick Check: Python Exceptions and Error Handling
Check your understanding of exceptions, handlers, cleanup, and raising errors.
~5 min read Start exercise -
Exercises
Quick Check: Python File I/O
Check your understanding of opening, reading, writing, closing, modes, and text versus binary file I/O.
~5 min read Start exercise -
Exercises
Quick Check: Python Function Parameter Kinds
Check positional-only, keyword-only, *args, and **kwargs parameters.
~5 min read Start exercise -
Exercises
Quick Check: Python Generator Control
Check your understanding of send(), throw(), close(), paused yields, exceptions, and generator cleanup.
~5 min read Start exercise -
Exercises
Quick Check: Python Generator Expressions
Check your understanding of generator-expression syntax, evaluation, iteration, and choosing between generators and comprehensions.
~5 min read Start exercise -
Exercises
Quick Check: Python Generators
Check your understanding of generator functions, yield, generator state, and generator expressions.
~5 min read Start exercise -
Exercises
Quick Check: Python Generic Type Parameters
Check your understanding of generic functions, classes, aliases, type-parameter scope, bounds, and defaults.
~5 min read Start exercise -
Exercises
Quick Check: Python Iterators
Check your understanding of Python iterables, iterator protocols, next(), StopIteration, and callable iterators with sentinels.
~5 min read Start exercise -
Exercises
Quick Check: Python JSON
Check your understanding of JSON serialization, deserialization, JSON files, mappings, and invalid input.
~5 min read Start exercise -
Exercises
Quick Check: Python Lambda Expressions
Check your understanding of lambda syntax, function objects, scope, and when to use def.
~5 min read Start exercise -
ExercisesIntermediate
Quick Check: Python Multiple Inheritance and Method Resolution Order
Check your understanding of multiple inheritance, MRO, and cooperative super().
~4 min read Start exercise -
Exercises
Quick Check: Python Names, Scopes, and Namespaces
Check your understanding of namespaces, name resolution, local bindings, UnboundLocalError, and global/nonlocal rebinding.
~5 min read Start exercise -
Exercises
Quick Check: Python Operator Precedence and Evaluation Order
Check your understanding of Python expression grouping, precedence, associativity, and evaluation order.
~5 min read Start exercise -
Exercises
Quick Check: Python Packages and Imports
Check your understanding of packages, __init__.py, dotted imports, and relative imports.
~5 min read Start exercise -
Exercises
Quick Check: Python Paths and pathlib
Check your understanding of path construction, traversal, path identity, lexical normalization, text and bytes path representations, path drive/root/tail decomposition, home and environment-variable expansion, path resolution, and selected os.path behavior.
~9 min read Start exercise -
Exercises
Quick Check: Python Properties and Managed Attributes
Check your understanding of Python properties, managed attributes, and cached computed values.
~7 min read Start exercise -
Exercises
Quick Check: Python Special Methods and Object Behavior
Check your understanding of Python special methods and how built-in operations and formatting customize objects.
~6 min read Start exercise -
Exercises
Quick Check: Python Structural Pattern Matching
Check your understanding of match, capture and value patterns, class patterns, guards, and OR patterns.
~5 min read Start exercise -
Exercises
Quick Check: Python TOML Configuration
Check your understanding of tomllib, TOML values, file parsing, float conversion, and invalid TOML.
~5 min read Start exercise -
Exercises
Quick Check: Python Type Alias Statements
Check your understanding of type aliases, TypeAliasType, lazy alias evaluation, annotations, and the distinction from type().
~5 min read Start exercise -
Exercises
Quick Check: Python With Statements and Context Managers
Check understanding of with, context-manager protocols, cleanup, narrow exception suppression, caller-owned resources with nullcontext(), and close()-only objects with closing().
~5 min read Start exercise -
Exercises
Quick Check: Python yield from
Check your understanding of generator delegation with yield from, delegated iterables, subgenerator return values, and ordinary yield.
~5 min read Start exercise -
ExercisesIntermediate
Quiz: Python Dataclasses
Check generated methods, field definitions, defaults, post-initialization, and frozen instances.
~6 min read Start exercise -
Exercises
Python Metaclasses and Class Creation Quiz
Assess class objects, the metaclass protocol, class-creation order, compatibility, and choosing a simpler mechanism.
~6 min read Start exercise -
ExercisesAdvanced
Quiz: Python Module Attribute Access
Check module-level fallback lookup, introspection, lazy attributes, and the boundary between attribute access and module globals.
~6 min read Start exercise -
ExercisesAdvanced
Quick Check: Python Union Types with |
Test union expressions, None unions, normalization, supported runtime checks, and the runtime generic boundary.
~6 min read Start exercise -
ExercisesIntermediate
Test your knowledge: argparse
Check argument types, flags, conflicts, subcommands, and testable command-line design.
~7 min read Start exercise -
ExercisesIntermediate
Test your knowledge: asynchronous unittest
Practise async test methods, awaited assertions, async fixtures, cleanup, and AsyncMock await checks.
~8 min read Start exercise -
ExercisesIntermediate
Test your knowledge: collections.Counter
Check Counter construction, missing-key behavior, count updates, most-common items, and multiset operations.
~6 min read Start exercise -
ExercisesIntermediate
Test your knowledge: collections.defaultdict
Check default factories, grouping, missing-key insertion, and the distinction from get() and Counter.
~6 min read Start exercise -
ExercisesIntermediate
Test your knowledge: command-line streams and exit status
Check command-line arguments, standard streams, exit status, and the boundary between sys and argparse.
~7 min read Start exercise -
ExercisesIntermediate
Test your knowledge: contextlib.ExitStack
Check dynamic resource acquisition, cleanup order, acquisition failure handling, cleanup ownership transfer, and combining synchronous and asynchronous managers with AsyncExitStack.
~8 min read Start exercise -
ExercisesIntermediate
Test your knowledge: dates and times
Check datetime types, durations, parsing, timezone awareness, and conversion.
~7 min read Start exercise -
ExercisesIntermediate
Test your knowledge: doctest
Practise executable docstrings, testmod and testfile, output matching, expected exceptions, and unittest integration.
~8 min read Start exercise -
ExercisesIntermediate
Test your knowledge: filecmp comparisons
Check shallow versus content comparison, cmpfiles results, directory-tree reports, caching, and tool selection.
~10 min read Start exercise -
ExercisesIntermediate
Test your knowledge: filesystem metadata
Check stat results, mode helpers, timestamps, symbolic links, and portability.
~9 min read Start exercise -
ExercisesIntermediate
Test your knowledge: function caching
Check when caching is safe, how cache and lru_cache differ, and how to inspect, invalidate, and constrain stored results.
~5 min read Start exercise -
ExercisesIntermediate
Test your knowledge: glob and fnmatch patterns
Check how to find pathname matches, filter filename strings, handle recursive and hidden paths, and escape literal wildcard characters.
~9 min read Start exercise -
ExercisesIntermediate
Test your knowledge: high-level file operations
Check your understanding of file copying, tree operations, deletion, disk usage, and safer archive extraction.
~8 min read Start exercise -
ExercisesIntermediate
Test your knowledge: itertools
Check lazy iterator pipelines, bounded slicing, batching, adjacent pairs, running aggregates, and combinatorial selections.
~6 min read Start exercise -
ExercisesIntermediate
Test your knowledge: os.scandir()
Check directory iteration, DirEntry type information, symlink handling, metadata caching, and filesystem errors.
~9 min read Start exercise -
ExercisesIntermediate
Check your understanding: partial functions and methods
Check argument pre-filling with functools.partial and instance-aware method variants with functools.partialmethod.
~5 min read Start exercise -
ExercisesIntermediate
Test your knowledge: Python Binary Search with bisect
Check insertion boundaries, duplicate handling, safe exact lookups, key functions, and the performance limits of bisect.
~5 min read Start exercise -
ExercisesIntermediate
Test your knowledge: Python environment variables
Check optional lookups, string conversion, validation, Boolean flags, and safe handling of configuration values.
~8 min read Start exercise -
ExercisesIntermediate
Test your knowledge: Python logging
Check logging levels, variable message data, logger/handler/formatter roles, exception tracebacks, and handler cleanup.
~7 min read Start exercise -
ExercisesIntermediate
Test your knowledge: Python Priority Queues
Check min-heap behavior, priority tie-breakers, heapify, and combined push/pop operations.
~6 min read Start exercise -
ExercisesIntermediate
Test your knowledge: Python regular expressions
Check pattern syntax, matching operations, capture groups, and text transformation with re.
~8 min read Start exercise -
ExercisesIntermediate
Test your knowledge: Python unittest
Check test discovery, useful assertions, expected exceptions, isolated fixtures, subtests, and command-line test execution.
~8 min read Start exercise -
ExercisesIntermediate
Test your knowledge: Python warnings
Check warning purpose, audience-specific categories, caller attribution, filtering, and warning tests.
~7 min read Start exercise -
ExercisesIntermediate
Test your knowledge: subprocess
Check safe argument passing, captured streams, child exit status, failures, and timeouts.
~7 min read Start exercise -
ExercisesIntermediate
Test your knowledge: TAR archives with tarfile
Check your understanding of TAR modes, compression, TarInfo members, member streams, and safe extraction.
~9 min read Start exercise -
ExercisesIntermediate
Test your knowledge: temporary files and directories
Check your understanding of temporary workspaces, named and unnamed files, spooled storage, and safe cleanup.
~8 min read Start exercise -
ExercisesIntermediate
Test your knowledge: unittest.mock
Practise Mock return values, side effects, safe patching, autospec, and meaningful interaction checks.
~8 min read Start exercise -
ExercisesIntermediate
Test your knowledge: ZIP archives with zipfile
Check your understanding of ZIP member names, reading and writing modes, compression, validation, and safe extraction.
~9 min read Start exercise