Re: [Tutor] Swapping values

2016-01-05 Thread Alan Gauld
On 05/01/16 00:37, yehudak . wrote: > In Python we can swap values between two variable a and b this way: > > a = 3; b = 7 > print(a, b) # => 3 7 > > a, b = b, a # swapping! > print(a, b) # => 7 3 > > How does this work? Steven has given you a detailed answer showing how Python d

Re: [Tutor] Swapping values

2016-01-04 Thread Steven D'Aprano
On Tue, Jan 05, 2016 at 02:37:27AM +0200, yehudak . wrote: > In Python we can swap values between two variable a and b this way: > > a = 3; b = 7 > print(a, b) # => 3 7 > > a, b = b, a # swapping! > print(a, b) # => 7 3 > > How does this work? The right-hand side of the assignmen

[Tutor] Swapping values

2016-01-04 Thread yehudak .
In Python we can swap values between two variable a and b this way: a = 3; b = 7 print(a, b) # => 3 7 a, b = b, a # swapping! print(a, b) # => 7 3 How does this work? If I split the 'magic' line into: a = b; b = a without a temp variable I get: print(a, b) # => 7 7 Thank