**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.
123456def 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)
To sum up Arbitrary Arguments:
- use a single asterisk (*) to unpack iterables.
- and use 2 asterisks (**) to unpack dictionaries.
Swipe to start coding
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.
Løsning
Takk for tilbakemeldingene dine!
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Awesome!
Completion rate improved to 5.56Awesome!
Completion rate improved to 5.56
**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.
123456def 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)
To sum up Arbitrary Arguments:
- use a single asterisk (*) to unpack iterables.
- and use 2 asterisks (**) to unpack dictionaries.
Swipe to start coding
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.
Løsning
Takk for tilbakemeldingene dine!
single
Awesome!
Completion rate improved to 5.56
**kwargs
Sveip for å vise menyen
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.
123456def 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)
To sum up Arbitrary Arguments:
- use a single asterisk (*) to unpack iterables.
- and use 2 asterisks (**) to unpack dictionaries.
Swipe to start coding
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.
Løsning
Takk for tilbakemeldingene dine!