Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100270
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Python variable assigning problems... |
| Date | 2015-12-11 09:36 -0700 |
| Message-ID | <mailman.143.1449851853.12405.python-list@python.org> (permalink) |
| References | <4b28ee3d-47b3-40ef-b48e-abff720635ed@googlegroups.com> <n4c0of$hqr$1@dont-email.me> <0098ce4a-966b-41df-bf06-352ad451134f@googlegroups.com> |
On Fri, Dec 11, 2015 at 9:10 AM, ICT Ezy <ictezy@gmail.com> wrote: > 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! This actually results in (2, 1), which is expected; you assign 1 to a and 2 to b and then swap the values. > x,y=y,x=2,3 > print(x,y) > # (3,2) --> Question: How to explain it? > # Not understand this process. Pl explain ... The assignments happen from left to right. First, (2,3) is assigned to (x,y), which has the effect of assigning 2 to x and then 3 to y. Next, (2,3) is assigned to (y,x), whas the effect of assigning 2 to y and then 3 to x, overwriting the previous assignments. Then when you do the print, x has the value 3, and y has the value 2.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Python variable assigning problems... ICT Ezy <ictezy@gmail.com> - 2015-12-09 09:49 -0800
Re: Python variable assigning problems... Joel Goldstick <joel.goldstick@gmail.com> - 2015-12-09 12:51 -0500
Re: Python variable assigning problems... Joel Goldstick <joel.goldstick@gmail.com> - 2015-12-09 12:52 -0500
Re: Python variable assigning problems... Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-09 21:38 +0000
Re: Python variable assigning problems... Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-12-10 16:33 +1100
Re: Python variable assigning problems... Denis McMahon <denismfmcmahon@gmail.com> - 2015-12-10 14:03 +0000
Re: Python variable assigning problems... ICT Ezy <ictezy@gmail.com> - 2015-12-11 08:10 -0800
Re: Python variable assigning problems... Robin Koch <robin.koch@t-online.de> - 2015-12-11 17:24 +0100
Re: Python variable assigning problems... Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-11 09:39 -0700
Re: Python variable assigning problems... Robin Koch <robin.koch@t-online.de> - 2015-12-11 18:52 +0100
Re: Python variable assigning problems... ICT Ezy <ictezy@gmail.com> - 2015-12-11 10:23 -0800
Re: Python variable assigning problems... ICT Ezy <ictezy@gmail.com> - 2015-12-11 10:05 -0800
Re: Python variable assigning problems... Michael Torrie <torriem@gmail.com> - 2015-12-11 11:20 -0700
Re: Python variable assigning problems... ICT Ezy <ictezy@gmail.com> - 2015-12-11 10:25 -0800
Re: Python variable assigning problems... Jussi Piitulainen <harvesting@is.invalid> - 2015-12-11 20:27 +0200
Re: Python variable assigning problems... ICT Ezy <ictezy@gmail.com> - 2015-12-11 10:54 -0800
Re: Python variable assigning problems... ICT Ezy <ictezy@gmail.com> - 2015-12-11 10:55 -0800
Re: Python variable assigning problems... ICT Ezy <ictezy@gmail.com> - 2015-12-11 10:00 -0800
Re: Python variable assigning problems... Michael Torrie <torriem@gmail.com> - 2015-12-11 11:10 -0700
Re: Python variable assigning problems... Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-11 09:36 -0700
csiph-web