Track 12 · Lesson 5 of 12
Decorators
Wrap functions to add logging, counting, validation and timing without touching their code, and understand what the @ syntax really does.
You will be able to
- Treat functions as values: pass them in, return them and store them
- Write a decorator with a wrapper that forwards *args and **kwargs and returns the result
- Explain that @decorator is shorthand for func = decorator(func)
- Use decorators for logging, counting calls and validating arguments
- Recognise when a decorator hides too much and plain code is better
Included with a Formula Quest membership
It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.
View Formula Quest memberships
Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.