values match | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

values match

I tried this example: a, b, *rest = [1,2,3,4] Without the squared brackets and still got in the interpreter an output with squared brackets. Can anyone help me differ?

6th May 2018, 2:31 PM
Elad Goldenberg
Elad Goldenberg - avatar
3 Answers
+ 1
You can’t store multiple values into a single variable that is not a list, dictionary, set ect. So you can do a, b, c, d = [1, 2, 3, 4] or a, b, *rest = [1, 2, 3, 4] c, d = rest
6th May 2018, 3:18 PM
TurtleShell
TurtleShell - avatar
0
a and b take 1 and 2 respectively. *rest will always be a list so Python doesn’t have to check how many values are leftover.
6th May 2018, 3:10 PM
TurtleShell
TurtleShell - avatar
0
Is it a matter of putting everything in parentheses?
6th May 2018, 3:14 PM
Elad Goldenberg
Elad Goldenberg - avatar