Python variable assigning problems...

Robin Koch robin.koch at t-online.de
Fri Dec 11 11:24:28 EST 2015


Am 11.12.2015 um 17:10 schrieb ICT Ezy:
> Dear All,
> Very Sorry for the my mistake here. I code here with mu question ...
>
> My Question:
>
> A,B=C,D=10,11
> print(A,B,C,D)
> #(10,11,10,11) --> This is OK!
>
> a=1; b=2
> a,b=b,a
> print(a,b)
> # (1,2) --> This is OK!
>
> x,y=y,x=2,3
> print(x,y)
> # (3,2) --> Question: How to explain it?
> # Not understand this process. Pl explain ...

What else would you expect?

Assigning goes from right to left:

x,y=y,x=2,3

<=>

y, x = 2, 3
x, y = y, x

Otherwise the assignment x, y = y, x would not make any sense, since x 
and y haven't any values yet.

And the execution from right to left is also a good choice, because one 
would like to do something like:

x = y = z = 0

Again, assigning from left to right woud lead to errors.

-- 
Robin Koch



More information about the Python-list mailing list