Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Packing and Unpacking Usage | Packing and Unpacking
Intermediate Python Techniques
course content

Conteúdo do Curso

Intermediate Python Techniques

Intermediate Python Techniques

1. Packing and Unpacking
2. Arguments in Function
3. Function as an Argument
4. Variable Scope
5. Decorators

book
Packing and Unpacking Usage

The most common usage of packing and unpacking can be seen in the following examples.

Values Swapping

Typically, to swap the values of variables, you might use an additional temporary variable:

Simply put, unpacking enables you to swap values between variables in a more concise manner:

Dropping Unneeded Values

If you only need the first values from an iterable object, you can pass the unneeded values to the *_ variable.

Note

We use '_' single underscore for ignoring values: It's common to use _ as a throwaway variable to indicate that a specific value in a tuple unpacking is intentionally being ignored.

1. What is the value of 'c' after it is executed?
2. What does the following code snippet accomplish?
3. What is the result of the following Python code?
What is the value of 'c' after it is executed?

What is the value of 'c' after it is executed?

Selecione a resposta correta

What does the following code snippet accomplish?

What does the following code snippet accomplish?

Selecione a resposta correta

What is the result of the following Python code?

What is the result of the following Python code?

Selecione a resposta correta

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

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