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

Conteúdo do 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

book**kwargs

Similar to *args, we use **kwargs to pass a variable number of named arguments. Similar to *args, if we put ** in front of a name, the name will accept any number of named arguments. A dictionary of several passed arguments will be available under this name. Let's look at the example.

123456
def grocery_cart(price_of_apples, **prices_of_other_fruits): print(price_of_apples) for value in prices_of_other_fruits.values(): print(value) grocery_cart(price_of_apples = 10, price_of_oranges = 7, price_of_carrots = 12)
copy

To sum up Arbitrary Arguments:

  • use a single asterisk (*) to unpack iterables.
  • and use 2 asterisks (**) to unpack dictionaries.

Tarefa

Code a function, named function, that will take in an unknown number of named arguments. This function runs for each argument using the for loop and prints only those longer than 6 characters.

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

book**kwargs

Similar to *args, we use **kwargs to pass a variable number of named arguments. Similar to *args, if we put ** in front of a name, the name will accept any number of named arguments. A dictionary of several passed arguments will be available under this name. Let's look at the example.

123456
def grocery_cart(price_of_apples, **prices_of_other_fruits): print(price_of_apples) for value in prices_of_other_fruits.values(): print(value) grocery_cart(price_of_apples = 10, price_of_oranges = 7, price_of_carrots = 12)
copy

To sum up Arbitrary Arguments:

  • use a single asterisk (*) to unpack iterables.
  • and use 2 asterisks (**) to unpack dictionaries.

Tarefa

Code a function, named function, that will take in an unknown number of named arguments. This function runs for each argument using the for loop and prints only those longer than 6 characters.

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

book**kwargs

Similar to *args, we use **kwargs to pass a variable number of named arguments. Similar to *args, if we put ** in front of a name, the name will accept any number of named arguments. A dictionary of several passed arguments will be available under this name. Let's look at the example.

123456
def grocery_cart(price_of_apples, **prices_of_other_fruits): print(price_of_apples) for value in prices_of_other_fruits.values(): print(value) grocery_cart(price_of_apples = 10, price_of_oranges = 7, price_of_carrots = 12)
copy

To sum up Arbitrary Arguments:

  • use a single asterisk (*) to unpack iterables.
  • and use 2 asterisks (**) to unpack dictionaries.

Tarefa

Code a function, named function, that will take in an unknown number of named arguments. This function runs for each argument using the for loop and prints only those longer than 6 characters.

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!

Similar to *args, we use **kwargs to pass a variable number of named arguments. Similar to *args, if we put ** in front of a name, the name will accept any number of named arguments. A dictionary of several passed arguments will be available under this name. Let's look at the example.

123456
def grocery_cart(price_of_apples, **prices_of_other_fruits): print(price_of_apples) for value in prices_of_other_fruits.values(): print(value) grocery_cart(price_of_apples = 10, price_of_oranges = 7, price_of_carrots = 12)
copy

To sum up Arbitrary Arguments:

  • use a single asterisk (*) to unpack iterables.
  • and use 2 asterisks (**) to unpack dictionaries.

Tarefa

Code a function, named function, that will take in an unknown number of named arguments. This function runs for each argument using the for loop and prints only those longer than 6 characters.

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