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 Techniques
course content

Contenido del Curso

Intermediate Python Techniques

Intermediate Python Techniques

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

bookChallenge: Create Your Decorator

Tarea

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 desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 5. Capítulo 3
toggle bottom row

bookChallenge: Create Your Decorator

Tarea

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 desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 5. Capítulo 3
toggle bottom row

bookChallenge: Create Your Decorator

Tarea

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 desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Tarea

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 desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 5. Capítulo 3
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
some-alt