writing functions
500+ articls more
100% Free • No Login • Updated Weekly • 2026 Ready
-
Docstrings
Docstring formats
Don't repeat yourself (DRY)
Pass by assignment
Immutable or Mutable
Using context managers
The yield keyword
Nested contexts
Two ways to define a context manager
Handling errors
Functions as objects
Functions as variables
Lists and dictionaries of functions
Referencing a function
Functions as arguments
Defining a function inside another function
Functions as return values
The global keyword
The nonlocal keyword
Attaching nonlocal variables to nested functions
Closures and deletion
Closures and overwriting
Definitions - nested function
Definitions - nonlocal variables
Decorators
decorator look like
The double_args decorator
Time a function
Using timer()
When to use decorators with timer()
Decorators and metadata
The timer decorator
Access to the original function
Decorators that take arguments
run_n_times()
A decorator factory
Timeout(): a real world example