Python Tutorial · Revision notes

Python Functions

A function is a named, reusable block of code. You will learn defining functions with def, lambda functions, important built-in functions, *args and **kwargs, and recursion.

Quick revision

  • def name(params): body; return gives the result, default None
  • Default values are evaluated once; avoid mutable defaults
  • lambda args: expression (single expression only)
  • any/all, enumerate, zip, sorted, map, filter are built-in
  • *args = tuple, **kwargs = dict; star at call site unpacks
  • Recursion needs a base case; limit about 1000; use lru_cache
Read the full Python Functions notes on Doubtclip →