Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Arbitrary Keyword Arguments (**kwargs) | Function Arguments in Details
Mastering Python: Annotations, Errors and Environment
course content

Conteúdo do Curso

Mastering Python: Annotations, Errors and Environment

Mastering Python: Annotations, Errors and Environment

1. Annotations
2. Function Arguments in Details
3. Error Handling
4. Virtual Environment

Arbitrary Keyword Arguments (**kwargs)

Arbitrary Keyword Arguments (**kwargs) are arbitrary arguments with name. Syntax of the keyword argument (keyword=argument). The **kwargs syntax allows us to pass a different number of named arguments.

In the example above, we pass the named arguments (first=11 and other) to the some_function().
The taken kwargs is a dict (dictionary) where:

  • keys are taken keywords in the str type.
  • values are values of these keywords.
key (keyword)value
first11
second22
some33

The operations with keywords are regular dict operations. You can use the keys() dictionary method to get all taken keywords and use the items() to get the key-value pairs:

1. What do you need to use to take a tuple of optional arguments?
2. What do you need to use to take a dict of keyword arguments?

What do you need to use to take a tuple of optional arguments?

Selecione a resposta correta

What do you need to use to take a dict of keyword arguments?

Selecione a resposta correta

Tudo estava claro?

Seção 2. Capítulo 4
We're sorry to hear that something went wrong. What happened?
some-alt