Key Ideas
1Why Functions?. A function is a named, reusable block of code that performs a specific task. Without functions, every time you need to calculate a grade or validate a password, you'd ...
2Parameters & Arguments. Parameters are the variable names in the function definition. Arguments are the actual values you pass when calling the function. Python has four parameter types — eac...
3Return Values. The return statement sends a value back to the caller and immediately exits the function. A function can return any Python object — a number, string, list, dict, tuple...
4Variable Scope — The LEGB Rule. When Python encounters a variable name, it searches for it in a specific order of scopes. This order is called the LEGB rule — Local → Enclosing → Global → Built-in.
5Lambda Functions & Higher-Order Functions. A lambda is a small anonymous function written in one line. It's syntactic sugar for a simple function — useful when you need a short function as an argument to anothe...