Python variable assigning problems...

ICT Ezy ictezy at gmail.com
Fri Dec 11 13:00:22 EST 2015


On Friday, December 11, 2015 at 8:24:45 AM UTC-8, Robin Koch wrote:
> 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

Thank you very much your answer, I had not known assignment id Right2Left before. I done it.



More information about the Python-list mailing list