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


Groups > comp.lang.python > #100270

Re: Python variable assigning problems...

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: Python variable assigning problems...
Date Fri, 11 Dec 2015 09:36:45 -0700
Lines 28
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>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de jzPk1RWRezZt7yfynKC4IwnDyQZ+1BdjaGVKxWh7sIkg==
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; 'subject:Python': 0.05; 'assigning': 0.09; '(2,': 0.16; '1),': 0.16; 'assignments': 0.16; 'assignments.': 0.16; 'ok!': 0.16; 'overwriting': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:variable': 0.16; 'wrote:': 0.16; 'all,': 0.20; '2015': 0.20; 'first,': 0.20; 'assign': 0.22; 'next,': 0.22; 'am,': 0.23; 'dec': 0.23; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'right.': 0.27; 'skip:# 10': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'question:': 0.29; 'code': 0.30; 'values.': 0.33; 'previous': 0.34; 'received:google.com': 0.35; 'received:209.85': 0.36; 'assigned': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'to:addr:python.org': 0.40; 'here.': 0.62; 'here': 0.66; 'results': 0.66; 'dear': 0.67; 'ict': 0.84; 'to:name:python': 0.84; 'mistake': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=Jk3yGDHwQXw86Lf96vKYNETwl382GZ84zrjXTx0EMSc=; b=mQqo1gGUt3AGsLqCHE1pkac69osogStt6BPPW0Mvzq1FjQvJM53h4MMF7kEOfac3Rm CX/yQ9vH+Nsw/HAjlU2sH+P2ViJggAbJKXA293GiH7wfgBagQYhcq8FuJ0qa7bEjRqJ7 Vn56/dE6uL6+WHlQNF4EA9YZbfVdNNLCBZh2v3y4D1Qx1JigoMexjTRo6vhraz0ZnY2u Zvr1I6mpbpAkloJME5AxpW+KFu8HS6gzbxTAkRbDz5q+pxqU7rI04iuz+/4x/DmRNJ20 Et5a7AnPFSdzbbJVcsSzqjvUIbpPL+MqqwyD7PU7JQR5boINpB8zflT9fPTB7LTfBHlz Ssug==
X-Received by 10.107.137.226 with SMTP id t95mr17253860ioi.188.1449851845092; Fri, 11 Dec 2015 08:37:25 -0800 (PST)
In-Reply-To <0098ce4a-966b-41df-bf06-352ad451134f@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:100270

Show key headers only | View raw


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 | NextPrevious in thread | Find similar | Unroll thread


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