Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100203 > unrolled thread

Python variable assigning problems...

Started byICT Ezy <ictezy@gmail.com>
First post2015-12-09 09:49 -0800
Last post2015-12-11 09:36 -0700
Articles 20 — 9 participants

Back to article view | Back to comp.lang.python


Contents

  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

#100203 — Python variable assigning problems...

FromICT Ezy <ictezy@gmail.com>
Date2015-12-09 09:49 -0800
SubjectPython variable assigning problems...
Message-ID<4b28ee3d-47b3-40ef-b48e-abff720635ed@googlegroups.com>
Pl refer question which attached image here:

link: https://drive.google.com/open?id=0B5L920jMv7T0dFNKQTJ2UUdudW8

[toc] | [next] | [standalone]


#100205

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2015-12-09 12:51 -0500
Message-ID<mailman.96.1449683492.12405.python-list@python.org>
In reply to#100203
On Wed, Dec 9, 2015 at 12:49 PM, ICT Ezy <ictezy@gmail.com> wrote:

> Pl refer question which attached image here:
>
> link: https://drive.google.com/open?id=0B5L920jMv7T0dFNKQTJ2UUdudW8
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com/stats/birthdays

[toc] | [prev] | [next] | [standalone]


#100206

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2015-12-09 12:52 -0500
Message-ID<mailman.97.1449683552.12405.python-list@python.org>
In reply to#100203
On Wed, Dec 9, 2015 at 12:51 PM, Joel Goldstick <joel.goldstick@gmail.com>
wrote:

>
>
> On Wed, Dec 9, 2015 at 12:49 PM, ICT Ezy <ictezy@gmail.com> wrote:
>
>> Pl refer question which attached image here:
>>
>> link: https://drive.google.com/open?id=0B5L920jMv7T0dFNKQTJ2UUdudW8
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
>
> You have a link to somewhere that needs permission to view.  Why not just
ask your question here?  Many people won't follow links, and anyway, no one
can follow yours

>
> --
> Joel Goldstick
> http://joelgoldstick.com/stats/birthdays
>



-- 
Joel Goldstick
http://joelgoldstick.com/stats/birthdays

[toc] | [prev] | [next] | [standalone]


#100210

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-12-09 21:38 +0000
Message-ID<mailman.101.1449697116.12405.python-list@python.org>
In reply to#100203
On 09/12/2015 17:49, ICT Ezy wrote:
> Pl refer question which attached image here:
>
> link: https://drive.google.com/open?id=0B5L920jMv7T0dFNKQTJ2UUdudW8
>

Please put your code, query or whatever it is inline here, I'm not going 
off into the great wide world just to suit you.

If it has anything to do with installing 3.5 on Windows asked and 
answered roughly one trillion times.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#100219

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2015-12-10 16:33 +1100
Message-ID<56690eb3$0$1584$c3e8da3$5496439d@news.astraweb.com>
In reply to#100203
On Thursday 10 December 2015 04:49, ICT Ezy wrote:

> Pl refer question which attached image here:
> 
> link: https://drive.google.com/open?id=0B5L920jMv7T0dFNKQTJ2UUdudW8

Do you really expect us to sign in to Google in order to help you?

Let me give you some friendly advice. You are asking us for free support. In 
the commercial world, this sort of support can cost hundreds of dollars an 
hour, and you are getting it for free. Every barrier you add, you lose 50% 
of the potential answers.

You ask us to click a link, instead of including the question direct in your 
message? That's 50% of potential helpers gone.

Link is to an image instead of actual text and code? That's 75% gone.

Link requires a login to Google? That's 87.5% gone.

If you want good quality answers, you need to ask good quality questions. If 
you ask lazy questions and expect us to do all the work, you'll probably be 
disappointed.



-- 
Steve

[toc] | [prev] | [next] | [standalone]


#100234

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-12-10 14:03 +0000
Message-ID<n4c0of$hqr$1@dont-email.me>
In reply to#100203
On Wed, 09 Dec 2015 09:49:26 -0800, ICT Ezy wrote:

> Pl refer question which attached image here:
> 
> link: https://drive.google.com/open?id=0B5L920jMv7T0dFNKQTJ2UUdudW8

I can't access the image with my G+ account because the image owner 
hasn't given me permission.

Perhaps you'd like to post a short self contained example of the problem 
here instead.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#100268

FromICT Ezy <ictezy@gmail.com>
Date2015-12-11 08:10 -0800
Message-ID<0098ce4a-966b-41df-bf06-352ad451134f@googlegroups.com>
In reply to#100234
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 ...

[toc] | [prev] | [next] | [standalone]


#100269

FromRobin Koch <robin.koch@t-online.de>
Date2015-12-11 17:24 +0100
Message-ID<n4etbt$mve$1@news.albasani.net>
In reply to#100268
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

[toc] | [prev] | [next] | [standalone]


#100271

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-12-11 09:39 -0700
Message-ID<mailman.144.1449852005.12405.python-list@python.org>
In reply to#100269
On Fri, Dec 11, 2015 at 9:24 AM, Robin Koch <robin.koch@t-online.de> wrote:
> 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.

No, it actually happens left to right. "x = y = z = 0" means "assign 0
to x, then assign 0 to y, then assign 0 to z." It doesn't mean "assign
0 to z, then assign z to y, etc." This works:

>>> d = d['foo'] = {}
>>> d
{'foo': {...}}

This doesn't:

>>> del d
>>> d['foo'] = d = {}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'd' is not defined

[toc] | [prev] | [next] | [standalone]


#100279

FromRobin Koch <robin.koch@t-online.de>
Date2015-12-11 18:52 +0100
Message-ID<n4f2hh$12u$1@news.albasani.net>
In reply to#100271
Am 11.12.2015 um 17:39 schrieb Ian Kelly:
> On Fri, Dec 11, 2015 at 9:24 AM, Robin Koch <robin.koch@t-online.de> wrote:
>> 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.
>
> No, it actually happens left to right. "x = y = z = 0" means "assign 0
> to x, then assign 0 to y, then assign 0 to z." It doesn't mean "assign
> 0 to z, then assign z to y, etc."

Oh. Ok, then, thanks for this correction.
Although it's consequent to use left-to-right precedence it's a little 
counter intuitive in the sense that the rightmost and leftmost objects 
interact. Especially with a background in mathematics. :-)

 > This works:
>
>>>> d = d['foo'] = {}
>>>> d
> {'foo': {...}}
>
> This doesn't:
>
>>>> del d
>>>> d['foo'] = d = {}
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> NameError: name 'd' is not defined

Good to know! Thank you.

-- 
Robin Koch

[toc] | [prev] | [next] | [standalone]


#100284

FromICT Ezy <ictezy@gmail.com>
Date2015-12-11 10:23 -0800
Message-ID<454d2836-4bd9-46f2-8407-6764746f8d3e@googlegroups.com>
In reply to#100279
On Friday, December 11, 2015 at 9:53:10 AM UTC-8, Robin Koch wrote:
> Am 11.12.2015 um 17:39 schrieb Ian Kelly:
> > On Fri, Dec 11, 2015 at 9:24 AM, Robin Koch <robin.koch@t-online.de> wrote:
> >> 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.
> >
> > No, it actually happens left to right. "x = y = z = 0" means "assign 0
> > to x, then assign 0 to y, then assign 0 to z." It doesn't mean "assign
> > 0 to z, then assign z to y, etc."
> 
> Oh. Ok, then, thanks for this correction.
> Although it's consequent to use left-to-right precedence it's a little 
> counter intuitive in the sense that the rightmost and leftmost objects 
> interact. Especially with a background in mathematics. :-)
> 
>  > This works:
> >
> >>>> d = d['foo'] = {}
> >>>> d
> > {'foo': {...}}
> >
> > This doesn't:
> >
> >>>> del d
> >>>> d['foo'] = d = {}
> > Traceback (most recent call last):
> >    File "<stdin>", line 1, in <module>
> > NameError: name 'd' is not defined
> 
> Good to know! Thank you.
> 
> -- 
> Robin Koch

Yeh, Your discussion is very good, really I understood correct process, Thank you very much all of you!  

[toc] | [prev] | [next] | [standalone]


#100281

FromICT Ezy <ictezy@gmail.com>
Date2015-12-11 10:05 -0800
Message-ID<b09aa197-1945-4df7-8de6-2f2aeb28aba6@googlegroups.com>
In reply to#100271
On Friday, December 11, 2015 at 8:40:18 AM UTC-8, Ian wrote:
> On Fri, Dec 11, 2015 at 9:24 AM, Robin Koch <robin.koch@t-online.de> wrote:
> > 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.
> 
> No, it actually happens left to right. "x = y = z = 0" means "assign 0
> to x, then assign 0 to y, then assign 0 to z." It doesn't mean "assign
> 0 to z, then assign z to y, etc." This works:
> 
> >>> d = d['foo'] = {}
> >>> d
> {'foo': {...}}
> 
> This doesn't:
> 
> >>> del d
> >>> d['foo'] = d = {}
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> NameError: name 'd' is not defined

Deat Ian,
Thank you very much your answer, but
above answer from Robin Koch and your answer is different. What's the actually process here? I agree with Robin Koch, but your answer is correct. Pl explain differences ?

[toc] | [prev] | [next] | [standalone]


#100283

FromMichael Torrie <torriem@gmail.com>
Date2015-12-11 11:20 -0700
Message-ID<mailman.151.1449858015.12405.python-list@python.org>
In reply to#100281
On 12/11/2015 11:05 AM, ICT Ezy wrote:
> Deat Ian, Thank you very much your answer, but above answer from
> Robin Koch and your answer is different. What's the actually process
> here? I agree with Robin Koch, but your answer is correct. Pl explain
> differences ?

If you go re-read the answers, you'll find Ian has explained why Robin
was incorrect, and Robin acknowledged he got it wrong.

[toc] | [prev] | [next] | [standalone]


#100285

FromICT Ezy <ictezy@gmail.com>
Date2015-12-11 10:25 -0800
Message-ID<44dc2682-0c94-4b82-bf5b-ca2016cda1b5@googlegroups.com>
In reply to#100283
On Friday, December 11, 2015 at 10:20:30 AM UTC-8, Michael Torrie wrote:
> On 12/11/2015 11:05 AM, ICT Ezy wrote:
> > Deat Ian, Thank you very much your answer, but above answer from
> > Robin Koch and your answer is different. What's the actually process
> > here? I agree with Robin Koch, but your answer is correct. Pl explain
> > differences ?
> 
> If you go re-read the answers, you'll find Ian has explained why Robin
> was incorrect, and Robin acknowledged he got it wrong.

OK. I got it!!!
Yeh, Your discussion is very good, really I understood correct process, Thank you very much all of you!

[toc] | [prev] | [next] | [standalone]


#100286

FromJussi Piitulainen <harvesting@is.invalid>
Date2015-12-11 20:27 +0200
Message-ID<lf5oadwhmd5.fsf@ling.helsinki.fi>
In reply to#100281
ICT Ezy writes:
> On Friday, December 11, 2015 at 8:40:18 AM UTC-8, Ian wrote:
>> 
>> No, it actually happens left to right. "x = y = z = 0" means "assign
>> 0 to x, then assign 0 to y, then assign 0 to z." It doesn't mean
>> "assign 0 to z, then assign z to y, etc." This works:
>> 
>> >>> d = d['foo'] = {}
>> >>> d
>> {'foo': {...}}
>> 
>> This doesn't:
>> 
>> >>> del d
>> >>> d['foo'] = d = {}
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> NameError: name 'd' is not defined
>
> Deat Ian,
> Thank you very much your answer, but
> above answer from Robin Koch and your answer is different. What's the
> actually process here? I agree with Robin Koch, but your answer is
> correct. Pl explain differences ?

Python language reference, at 7.2 Assignment statements, says this:

# An assignment statement evaluates the expression list (remember that
# this can be a single expression or a comma-separated list, the latter
# yielding a tuple) and assigns the single resulting object to each of
# the target lists, from left to right.

To simplify a bit, it's talking about a statement of this form:

     target_list = target_list = target_list = expression_list

And it says what Ian said: the value of the expression is assigned to
each target *from left to right*.

<https://docs.python.org/3/reference/simple_stmts.html#assignment-statements>

[toc] | [prev] | [next] | [standalone]


#100295

FromICT Ezy <ictezy@gmail.com>
Date2015-12-11 10:54 -0800
Message-ID<1b4b5564-3e1f-4216-9497-455997384bcf@googlegroups.com>
In reply to#100286
On Friday, December 11, 2015 at 10:27:29 AM UTC-8, Jussi Piitulainen wrote:
> ICT Ezy writes:
> > On Friday, December 11, 2015 at 8:40:18 AM UTC-8, Ian wrote:
> >> 
> >> No, it actually happens left to right. "x = y = z = 0" means "assign
> >> 0 to x, then assign 0 to y, then assign 0 to z." It doesn't mean
> >> "assign 0 to z, then assign z to y, etc." This works:
> >> 
> >> >>> d = d['foo'] = {}
> >> >>> d
> >> {'foo': {...}}
> >> 
> >> This doesn't:
> >> 
> >> >>> del d
> >> >>> d['foo'] = d = {}
> >> Traceback (most recent call last):
> >>   File "<stdin>", line 1, in <module>
> >> NameError: name 'd' is not defined
> >
> > Deat Ian,
> > Thank you very much your answer, but
> > above answer from Robin Koch and your answer is different. What's the
> > actually process here? I agree with Robin Koch, but your answer is
> > correct. Pl explain differences ?
> 
> Python language reference, at 7.2 Assignment statements, says this:
> 
> # An assignment statement evaluates the expression list (remember that
> # this can be a single expression or a comma-separated list, the latter
> # yielding a tuple) and assigns the single resulting object to each of
> # the target lists, from left to right.
> 
> To simplify a bit, it's talking about a statement of this form:
> 
>      target_list = target_list = target_list = expression_list
> 
> And it says what Ian said: the value of the expression is assigned to
> each target *from left to right*.
> 
> <https://docs.python.org/3/reference/simple_stmts.html#assignment-statements>

Yes you correct!

[toc] | [prev] | [next] | [standalone]


#100296

FromICT Ezy <ictezy@gmail.com>
Date2015-12-11 10:55 -0800
Message-ID<b115fb40-2f78-4234-b3ff-98d813973f4c@googlegroups.com>
In reply to#100286
On Friday, December 11, 2015 at 10:27:29 AM UTC-8, Jussi Piitulainen wrote:
> ICT Ezy writes:
> > On Friday, December 11, 2015 at 8:40:18 AM UTC-8, Ian wrote:
> >> 
> >> No, it actually happens left to right. "x = y = z = 0" means "assign
> >> 0 to x, then assign 0 to y, then assign 0 to z." It doesn't mean
> >> "assign 0 to z, then assign z to y, etc." This works:
> >> 
> >> >>> d = d['foo'] = {}
> >> >>> d
> >> {'foo': {...}}
> >> 
> >> This doesn't:
> >> 
> >> >>> del d
> >> >>> d['foo'] = d = {}
> >> Traceback (most recent call last):
> >>   File "<stdin>", line 1, in <module>
> >> NameError: name 'd' is not defined
> >
> > Deat Ian,
> > Thank you very much your answer, but
> > above answer from Robin Koch and your answer is different. What's the
> > actually process here? I agree with Robin Koch, but your answer is
> > correct. Pl explain differences ?
> 
> Python language reference, at 7.2 Assignment statements, says this:
> 
> # An assignment statement evaluates the expression list (remember that
> # this can be a single expression or a comma-separated list, the latter
> # yielding a tuple) and assigns the single resulting object to each of
> # the target lists, from left to right.
> 
> To simplify a bit, it's talking about a statement of this form:
> 
>      target_list = target_list = target_list = expression_list
> 
> And it says what Ian said: the value of the expression is assigned to
> each target *from left to right*.
> 
> <https://docs.python.org/3/reference/simple_stmts.html#assignment-statements>
See also:

>>> x = [5, 6]
>>> x[i],x[j]
(5, 6)
>>> i,j=0,1
>>> x[i],x[j]=x[j],x[i]=2,3
>>> x[i],x[j]
(3, 2)

[toc] | [prev] | [next] | [standalone]


#100280

FromICT Ezy <ictezy@gmail.com>
Date2015-12-11 10:00 -0800
Message-ID<52c10154-fa91-4f47-af9e-58c3c9aa6588@googlegroups.com>
In reply to#100269
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.

[toc] | [prev] | [next] | [standalone]


#100282

FromMichael Torrie <torriem@gmail.com>
Date2015-12-11 11:10 -0700
Message-ID<mailman.150.1449857432.12405.python-list@python.org>
In reply to#100280
On 12/11/2015 11:00 AM, ICT Ezy wrote:
> Thank you very much your answer, I had not known assignment id Right2Left before. I done it.

Except that Robin was mistaken.  Assignment is indeed left to right,
though what's being assigned is on the right.

> 

[toc] | [prev] | [next] | [standalone]


#100270

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-12-11 09:36 -0700
Message-ID<mailman.143.1449851853.12405.python-list@python.org>
In reply to#100268
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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web