0
a, b = b, a?
a =5 b = 6 a, b = b, a print(a) Solution: 6 5, 6 = 6, 5 # i think this is what python is thinking print (a) #a=5. Print 5. So, why did it print six? At whatpoint did a and b switch values? Also, in prior posts people have pointed out the difference between having the same value (5 and 6 here) but be different objects. So super confused here. Thanks for any help:)
4 Respostas
+ 7
a, b = b, a
Basically, this is a way of swapping values of variables. a will be assigned value of b and b will be assigned the value of a. Basically, this doesn't work with integers as they have fixed value. They can't change their value.
+ 3
This thing means swapping the values of the variables.this is not comparing the values of the variables.remember that when we compare values we use double == and when we assign the values to the variable we use single =.
a=5
b=6
a,b=b,a
Now a become b and b become a.
+ 2
a = 5
b = 6
a,b = b,a
means
(a,b) =(6,5)
+ 1
Thanks everyone:)!