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

Conteúdo do Curso

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

Tarefa

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 desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 5. Capítulo 3
toggle bottom row

bookChallenge: Create Your Decorator

Tarefa

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 desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 5. Capítulo 3
toggle bottom row

bookChallenge: Create Your Decorator

Tarefa

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 desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Tarefa

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 desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 5. Capítulo 3
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
some-alt