Back to questions
JuniorTheoryCommon
What does the program print?
first, *middle, last = [1, 2, 3, 4]
a, b = 1, 2
a, b = b, a + b
print(middle, a, b)[2, 3] 2 3
- Expecting
bto be4, as ifachanged first: the right sideb, a + bis computed in full from the old values, giving2, 3, before either name changes. - Expecting a tuple
(2, 3): a starred target always collects its values into alist, whatever the right side is.
- What does
first, *middle, last = [1, 2]put inmiddle? - What happens with
a, b = [1, 2, 3]?