Back to Notes

Python Topics

Quick Nav

AreaNotes
Language Core[[Python Programming]] · [[Decorators]] · [[Object Oriented Programming]]
Libraries[[Logging]]
Interview Prep[[Python Interview Questions]]

Language Core Checklist

  • First-class functions, higher-order functions, pure functions
  • Functional tools — map, filter, reduce
  • Generators & yield
  • Generator expressions
  • Enums
  • ord(), chr()
  • Decorators — 3-level nested pattern, functools.wraps
  • OOP — classes, __init__, self, instance vs class variables
  • Encapsulation (__private)
  • Inheritance & super()
  • Polymorphism, operator overloading (__add__, __eq__, etc.)
  • Context managers (with, __enter__/__exit__)
  • Abstract classes (abc.ABC, @abstractmethod)
  • Dataclasses (@dataclass)
  • Type hints & typing module
  • *args / **kwargs
  • List/dict/set comprehensions
  • lambda functions
  • itertools / functools

Python for DSA (Interview-Specific)

# Useful built-ins
sorted(lst, key=lambda x: x[1])     # sort by second element
heapq.nlargest(k, lst)              # top-k
collections.Counter(lst)            # frequency map
collections.defaultdict(list)       # graph adjacency list
collections.deque(maxlen=k)         # sliding window / BFS queue
bisect.bisect_left(lst, target)     # binary search on sorted list

# Infinity
float('inf')   # positive
float('-inf')  # negative

# Integer division / modulo
7 // 2   # 3
7 % 2    # 1
divmod(7, 2)  # (3, 1)

# String tricks
''.join(lst)           # join list of chars
s[::-1]                # reverse string
ord('a'), chr(97)      # char ↔ int

# Swap without temp
a, b = b, a

Libraries Checklist

  • logging — levels, handlers, structured logging
  • os / pathlib — file system operations
  • json — serialize/deserialize
  • datetime — dates, timezones
  • re — regex
  • requests / httpx — HTTP clients
  • asyncio — async/await, event loop
  • pytest — testing
  • pydantic — data validation (heavily used in FastAPI / LangChain)
  • FastAPI — async web framework
  • SQLAlchemy — ORM

Interview Topics (Python-Specific)

QuestionKey Points
Mutable vs immutable typesLists/dicts mutable; str/int/tuple immutable; default arg [] gotcha
GIL (Global Interpreter Lock)Only one thread runs Python bytecode at a time; use multiprocessing for CPU work
is vs ==is checks identity (same object in memory); == checks value
deepcopy vs copyShallow copy copies refs; deep copy recursively copies values
__slots__Restrict instance attributes, reduce memory overhead
@propertyGetter/setter without changing API
@classmethod vs @staticmethodclassmethod gets cls; staticmethod gets neither self nor cls