Code Explanation:
a, b, c = (1, 2, 3)
This is tuple unpacking. The tuple (1, 2, 3) is unpacked, assigning:
a = 1
b = 2
c = 3
a, b = b, a + b
This is another unpacking operation. The right-hand side of the assignment b, a + b is evaluated first, and then assigned to a and b:
b (the current value of b) is 2.
a + b (current values: 1 + 2) is 3.
The tuple (2, 3) is unpacked and assigned:
a = 2
b = 3
At this point:
a = 2
b = 3
c = 3 (unchanged from the initial assignment)
print(a, b, c)
This prints the values of a, b, and c:
Output: 2 3 3
Final Output:
2 3 3
0 Comments:
Post a Comment