Conteúdo do Curso
Intermediate Python: Arguments, Scopes and Decorators
Intermediate Python: Arguments, Scopes and Decorators
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.
Obrigado pelo seu feedback!