Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Arbitrary Keyword Arguments | Arbitrary Arguments
Python Functions Tutorial
course content

Conteúdo do Curso

Python Functions Tutorial

Python Functions Tutorial

1. What is a Function in Python?
2. Positional and Optional Arguments
3. Arbitrary Arguments
4. Function Return Value Specification
5. Recursion and Lambda Functions

bookArbitrary Keyword Arguments

In programming, there is a special syntax for passing any number of named parameters to a function, known as **kwargs.

**kwargs allows a function to accept any number of named arguments and treat them as a dictionary.

123456
def example_function(**kwargs): for key, value in kwargs.items(): print(f'{key}: {value}') # Example function call example_function(name='John', age=25, city='New York')
copy

In this example, **kwargs receives named arguments and prints their keys and values.

Note

The .items() method is used to obtain a list of key-value pairs from a dictionary in Python. Each element in this list is represented as a tuple (key, value).

Tarefa
test

Swipe to show code editor

  1. Complete the code in the function definition to allow it to accept a variable number of key-value pairs representing item names and their costs using keyword arguments kwargs.
  2. Complete the code in the loop to correctly calculate the total cost of the items stored in the kwargs variable.

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

bookArbitrary Keyword Arguments

In programming, there is a special syntax for passing any number of named parameters to a function, known as **kwargs.

**kwargs allows a function to accept any number of named arguments and treat them as a dictionary.

123456
def example_function(**kwargs): for key, value in kwargs.items(): print(f'{key}: {value}') # Example function call example_function(name='John', age=25, city='New York')
copy

In this example, **kwargs receives named arguments and prints their keys and values.

Note

The .items() method is used to obtain a list of key-value pairs from a dictionary in Python. Each element in this list is represented as a tuple (key, value).

Tarefa
test

Swipe to show code editor

  1. Complete the code in the function definition to allow it to accept a variable number of key-value pairs representing item names and their costs using keyword arguments kwargs.
  2. Complete the code in the loop to correctly calculate the total cost of the items stored in the kwargs variable.

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

bookArbitrary Keyword Arguments

In programming, there is a special syntax for passing any number of named parameters to a function, known as **kwargs.

**kwargs allows a function to accept any number of named arguments and treat them as a dictionary.

123456
def example_function(**kwargs): for key, value in kwargs.items(): print(f'{key}: {value}') # Example function call example_function(name='John', age=25, city='New York')
copy

In this example, **kwargs receives named arguments and prints their keys and values.

Note

The .items() method is used to obtain a list of key-value pairs from a dictionary in Python. Each element in this list is represented as a tuple (key, value).

Tarefa
test

Swipe to show code editor

  1. Complete the code in the function definition to allow it to accept a variable number of key-value pairs representing item names and their costs using keyword arguments kwargs.
  2. Complete the code in the loop to correctly calculate the total cost of the items stored in the kwargs variable.

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!

In programming, there is a special syntax for passing any number of named parameters to a function, known as **kwargs.

**kwargs allows a function to accept any number of named arguments and treat them as a dictionary.

123456
def example_function(**kwargs): for key, value in kwargs.items(): print(f'{key}: {value}') # Example function call example_function(name='John', age=25, city='New York')
copy

In this example, **kwargs receives named arguments and prints their keys and values.

Note

The .items() method is used to obtain a list of key-value pairs from a dictionary in Python. Each element in this list is represented as a tuple (key, value).

Tarefa
test

Swipe to show code editor

  1. Complete the code in the function definition to allow it to accept a variable number of key-value pairs representing item names and their costs using keyword arguments kwargs.
  2. Complete the code in the loop to correctly calculate the total cost of the items stored in the kwargs variable.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 3. Capítulo 2
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt