Subject revision

Python

Core Python interview recall cards.

Clear

Results update as you type. Press / to jump straight into search.

Python cards

64 cards

Python Medium Theory

Built-in exceptions, try/except/else/finally, custom exceptions, and chaining

Python exception handling is strongest when you catch specific built-in errors, use `else` for the success path, `finally` for cleanup, and custom exceptions when domain meaning matters.

  • Catch only expected failures
  • `else` runs when no exception occurred
  • `raise ... from ...` preserves causal context

Built-in exceptions, try/except/else/finally, custom exceptions, and chaining

Python Medium Theory

collections and functools helpers: `defaultdict`, `Counter`, `deque`, `namedtuple`, `partial`, `reduce`, and `lru_cache`

These helpers reduce boilerplate for grouping, counting, queue behavior, lightweight record types, partial application, reduction, and memoization.

  • `Counter` counts fast
  • `deque` is strong for queues
  • `lru_cache` adds memoization with little code

collections and functools helpers: `defaultdict`, `Counter`, `deque`, `namedtuple`, `partial`, `reduce`, and `lru_cache`

Python Medium Theory

Common Python comparison topics: set vs list, append vs extend, remove vs pop vs del, sort() vs sorted(), @staticmethod vs @classmethod, and generator vs iterator

Interview prep often comes down to comparing similar tools and explaining when each one is the better fit.

  • Lists preserve order, sets optimize membership
  • append adds one item while extend adds many
  • sorted returns a new list while sort mutates in place

Common Python comparison topics: set vs list, append vs extend, remove vs pop vs del, sort() vs sorted(), @staticmethod vs @classmethod, and generator vs iterator

Python Medium Theory

Common special methods like `__str__`, `__repr__`, `__len__`, `__getitem__`, and `__contains__`

Special methods let your objects behave like built-in types in printing, indexing, length checks, and membership operations.

  • `__str__` is user-friendly output
  • `__repr__` should be unambiguous
  • Container protocols come from dunder methods

Common special methods like `__str__`, `__repr__`, `__len__`, `__getitem__`, and `__contains__`

Python Medium Theory

Conditional statements, ternary expressions, and match-case basics

Python uses `if`/`elif`/`else` for general branching, a ternary expression for concise value selection, and `match-case` for structural pattern matching in newer versions.

  • Use ternary for small expressions only
  • match-case compares shapes and patterns
  • Readable branching beats clever branching

Conditional statements, ternary expressions, and match-case basics

Python Easy Theory

Core data types in Python

Core Python data types include numbers, strings, lists, tuples, sets, dictionaries, booleans, and `None`.

  • Mutable and immutable types differ
  • Some are ordered, some are hash-based
  • Choose types based on access and update patterns

Core data types in Python