Interview Questions
Python Interview Questions
Python interview questions and answers, organized by topic, with examples and key points for quick revision.
Python Basics
Python as a language -- what makes it high-level and dynamically typed, and how CPython actually runs a program.
Open 5 questionsData Types & Variables
Variables, built-in data types, dynamic vs strong typing, and Python's core equality and mutability rules.
Open 10 questionsLists, Tuples, Sets & Dictionaries
Lists, tuples, sets, dictionaries, comprehensions, slicing, unpacking, and the built-in methods that manipulate them.
Open 15 questionsFunctions
Function definitions, argument passing, *args/**kwargs, lambdas, decorators, recursion, and variable scope.
Open 15 questionsStrings
Python's immutable string type -- formatting, splitting, joining, and Unicode handling.
Open 8 questionsException Handling
try/except/else/finally, raising and chaining exceptions, and custom exception design.
Open 8 questionsOOP
Classes, objects, constructors, inheritance, MRO, polymorphism, encapsulation, abstraction, and property-based APIs.
Open 14 questionsFile Handling
Opening files, file modes, and why context managers are the safe way to work with them.
Open 3 questionsModules & Packages
Modules, packages, the import system, pip, and the script-vs-import execution guard.
Open 9 questionsIterators, Generators & Functional Tools
Iterables, iterators, generators, and the built-in functional tools -- enumerate, zip, map, filter, reduce.
Open 14 questionsMultithreading & Concurrency
Threading, the GIL, multiprocessing, concurrent.futures, asyncio, and safe coordination of concurrent work.
Open 9 questionsMemory Management
Reference counting, garbage collection, shallow vs deep copy, object identity, weak references, and context managers.
Open 14 questionsAdvanced Python
Type hints, duck typing, EAFP/LBYL, monkey patching, introspection, __slots__, hashability, closures, and descriptors.
Open 15 questionsSpecial Methods & Operator Overloading
Dunder methods for equality, representation, construction, and operator overloading, plus common OOP design patterns.
Open 10 questionsTesting & Tooling
Logging, unit testing, pytest, calling REST APIs safely, and preventing SQL injection.
Open 6 questionsSerialization & Data Interchange
Converting Python objects to and from JSON and pickle, and the safety trade-offs between them.
Open 4 questionsPython Runtime Internals
The Python virtual machine, bytecode, and the __pycache__ bytecode cache.
Open 3 questionsEnvironment, CLI & Packaging
Virtual environments, dependency management, pyproject.toml/wheels, and Python's environment/CLI/filesystem standard library.
Open 17 questionsAlgorithms & Data Structures
Time/space complexity, common data-structure patterns (Counter, deque, stack, queue, heap), sorting, and caching.
Open 29 questionsTyping & Modern Python Syntax
namedtuple, Protocol, Optional/Union, match-case, the walrus operator, and positional-/keyword-only parameters.
Open 12 questionsBuiltins, Control Flow & Scope
any()/all(), loop control flow, scope, closures, and Python's namespace model.
Open 14 questionsType Checking & Abstract Classes
isinstance/issubclass, ABC virtual subclasses, namespace packages, and dynamic/lazy imports.
Open 6 questions