Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Create Your Decorator | Decorators
Intermediate Python: Arguments, Scopes and Decorators
course content

Course Content

Intermediate Python: Arguments, Scopes and Decorators

Intermediate Python: Arguments, Scopes and Decorators

1. Packing and Unpacking
2. Arguments in Function
3. Function as an Argument
4. Variable Scope
5. Decorators

bookChallenge: Create Your Decorator

Task

Sometimes, it's necessary to measure how long a particular function or code segment takes to execute. This can be achieved by calculating the time elapsed from the start to the end of the function. However, if you need to measure the execution time of multiple functions, a more efficient approach would be to write a single decorator and apply it to these functions.

We'll develop such a decorator and see its effectiveness:

  1. You need to define the parameters that the wrapper will accept;
  2. Call the func function with the arguments *args and **kwargs, and assign it to the result variable;
  3. In the line return ___, you should return result;
  4. Complete the decorator by returning the wrapper function;
  5. Applies the time_it decorator to the factorial function;
  6. Calls the factorial function (which is now decorated with time_it) and prints its return value.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 5. Chapter 3
toggle bottom row

bookChallenge: Create Your Decorator

Task

Sometimes, it's necessary to measure how long a particular function or code segment takes to execute. This can be achieved by calculating the time elapsed from the start to the end of the function. However, if you need to measure the execution time of multiple functions, a more efficient approach would be to write a single decorator and apply it to these functions.

We'll develop such a decorator and see its effectiveness:

  1. You need to define the parameters that the wrapper will accept;
  2. Call the func function with the arguments *args and **kwargs, and assign it to the result variable;
  3. In the line return ___, you should return result;
  4. Complete the decorator by returning the wrapper function;
  5. Applies the time_it decorator to the factorial function;
  6. Calls the factorial function (which is now decorated with time_it) and prints its return value.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 5. Chapter 3
toggle bottom row

bookChallenge: Create Your Decorator

Task

Sometimes, it's necessary to measure how long a particular function or code segment takes to execute. This can be achieved by calculating the time elapsed from the start to the end of the function. However, if you need to measure the execution time of multiple functions, a more efficient approach would be to write a single decorator and apply it to these functions.

We'll develop such a decorator and see its effectiveness:

  1. You need to define the parameters that the wrapper will accept;
  2. Call the func function with the arguments *args and **kwargs, and assign it to the result variable;
  3. In the line return ___, you should return result;
  4. Complete the decorator by returning the wrapper function;
  5. Applies the time_it decorator to the factorial function;
  6. Calls the factorial function (which is now decorated with time_it) and prints its return value.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Task

Sometimes, it's necessary to measure how long a particular function or code segment takes to execute. This can be achieved by calculating the time elapsed from the start to the end of the function. However, if you need to measure the execution time of multiple functions, a more efficient approach would be to write a single decorator and apply it to these functions.

We'll develop such a decorator and see its effectiveness:

  1. You need to define the parameters that the wrapper will accept;
  2. Call the func function with the arguments *args and **kwargs, and assign it to the result variable;
  3. In the line return ___, you should return result;
  4. Complete the decorator by returning the wrapper function;
  5. Applies the time_it decorator to the factorial function;
  6. Calls the factorial function (which is now decorated with time_it) and prints its return value.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 5. Chapter 3
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt