Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
*args | An Unknown Number of Arguments
Python Functions: From Zero to Hero
course content

Contenido del Curso

Python Functions: From Zero to Hero

Python Functions: From Zero to Hero

1. What is a Function?
2. Arguments or Parameters
3. Assigning a Default Value to a Parameter
4. An Unknown Number of Arguments
5. Functions within Functions
6. Recursion

*args

*args is needed when we want to pass an unknown number of unnamed arguments. If we put * before the name of the variable, this name will take not one argument, but several. Arguments are passed as a tuple and are available inside the function under the same name as the parameter name, only without *. Let's look at the example.

123456
def grocery_cart(*prices_of_all_fruits): total_price = 0 for i in prices_of_all_fruits: total_price = total_price + i print(total_price) grocery_cart(10, 7, 12, 13)
copy

It's time to practice.

Tarea

You have to implement a function, named multiply_elements, that will take in an unknown number of arguments and multiply all of them together. Run created a function for this set of numbers:

  • (3, 6, 1, 2)

Tarea

You have to implement a function, named multiply_elements, that will take in an unknown number of arguments and multiply all of them together. Run created a function for this set of numbers:

  • (3, 6, 1, 2)

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 4. Capítulo 2
toggle bottom row

*args

*args is needed when we want to pass an unknown number of unnamed arguments. If we put * before the name of the variable, this name will take not one argument, but several. Arguments are passed as a tuple and are available inside the function under the same name as the parameter name, only without *. Let's look at the example.

123456
def grocery_cart(*prices_of_all_fruits): total_price = 0 for i in prices_of_all_fruits: total_price = total_price + i print(total_price) grocery_cart(10, 7, 12, 13)
copy

It's time to practice.

Tarea

You have to implement a function, named multiply_elements, that will take in an unknown number of arguments and multiply all of them together. Run created a function for this set of numbers:

  • (3, 6, 1, 2)

Tarea

You have to implement a function, named multiply_elements, that will take in an unknown number of arguments and multiply all of them together. Run created a function for this set of numbers:

  • (3, 6, 1, 2)

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 4. Capítulo 2
toggle bottom row

*args

*args is needed when we want to pass an unknown number of unnamed arguments. If we put * before the name of the variable, this name will take not one argument, but several. Arguments are passed as a tuple and are available inside the function under the same name as the parameter name, only without *. Let's look at the example.

123456
def grocery_cart(*prices_of_all_fruits): total_price = 0 for i in prices_of_all_fruits: total_price = total_price + i print(total_price) grocery_cart(10, 7, 12, 13)
copy

It's time to practice.

Tarea

You have to implement a function, named multiply_elements, that will take in an unknown number of arguments and multiply all of them together. Run created a function for this set of numbers:

  • (3, 6, 1, 2)

Tarea

You have to implement a function, named multiply_elements, that will take in an unknown number of arguments and multiply all of them together. Run created a function for this set of numbers:

  • (3, 6, 1, 2)

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

¿Todo estuvo claro?

*args is needed when we want to pass an unknown number of unnamed arguments. If we put * before the name of the variable, this name will take not one argument, but several. Arguments are passed as a tuple and are available inside the function under the same name as the parameter name, only without *. Let's look at the example.

123456
def grocery_cart(*prices_of_all_fruits): total_price = 0 for i in prices_of_all_fruits: total_price = total_price + i print(total_price) grocery_cart(10, 7, 12, 13)
copy

It's time to practice.

Tarea

You have to implement a function, named multiply_elements, that will take in an unknown number of arguments and multiply all of them together. Run created a function for this set of numbers:

  • (3, 6, 1, 2)

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 4. Capítulo 2
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