The below works
a = 0
b = 1
a, b = b, a
print(a, b) # 1 0
But the below does not work:
l = [3, 6, 9]
a = 0
a, l[a] = l[a], a # IndexError: list assignment index out of range
How does tuple assignment work in Python?
The below works
a = 0
b = 1
a, b = b, a
print(a, b) # 1 0
But the below does not work:
l = [3, 6, 9]
a = 0
a, l[a] = l[a], a # IndexError: list assignment index out of range
How does tuple assignment work in Python?