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

Contenido del 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

Challenge: 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.

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.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

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

Challenge: 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.

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.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

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

Challenge: 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.

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.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

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.

Cambia 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
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt