Help me understand difference between list assignment.
I have found that assignment like this
a[0] = b[0]
b[0] = a[0]
Is different from
a[0], b[0] = b[0], a[0]
The values of a and b in both the cases are different , however both of these assignment methods does the same , swapping.
You can run my sample code to see this
a = [0,1,2]
b = [3,4,5]
print "Value of a and b before swaping :"
print "value of a :" , a
print "value of b :" , b
print "\nswap in two line"
a[0] = b[0]
b[0] = a[0]
print "value of a :" , a
print "value of b :" , b
print "\nswap in one line"
# Reinitilizing value of a and b before performing swaping
a = [0,1,2]
b = [3,4,5]
a[0], b[0] = b[0], a[0]
print "value of a :" , a
print "value of b :" , b
How are two methods of assignment different? At the first glance they look the same and do the same thing.