Noe Vazz
Noe Vazz

Reputation: 13

Multiple assigment to variable in same line (Python 3)

how does this script works and why the variable b get 50 as its value and not 1

a = 1
b = 50
b, b = a, b
print(b)

actual result: 50

Upvotes: 1

Views: 34

Answers (1)

DeepSpace
DeepSpace

Reputation: 81594

b, b = a, b is actually a tuple assignment, and it works from left to right.

b, b = a, b evaluates to (b, b) = (1, 50) which in turn is executed as

b = 1
b = 50

Upvotes: 2

Related Questions