Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Packing in Python: Grouping Multiple Values into a Single Variable | Mastering Packing and Unpacking in Python
Intermediate Python Techniques
course content

Kursinnhold

Intermediate Python Techniques

Intermediate Python Techniques

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

book
Packing in Python: Grouping Multiple Values into a Single Variable

To pack multiple variables, you need to use the * iterable unpacking operator. Simply place an asterisk * before the variable, and it will pack any number of variables. Packing a variable is only possible within a tuple or a list.

python

But the SyntaxError will occur if to use more than one unpacking operator.

1
*a, *b = 1, 2, 3, 4
copy
1
*a, *b, *c = 1, 2, 3
copy
question mark

Can you use more than one iterable unpacking operator in a single expression?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 2
Vi beklager at noe gikk galt. Hva skjedde?
some-alt