Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: Python variable assigning problems... Date: Fri, 11 Dec 2015 09:36:45 -0700 Lines: 28 Message-ID: References: <4b28ee3d-47b3-40ef-b48e-abff720635ed@googlegroups.com> <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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100270 On Fri, Dec 11, 2015 at 9:10 AM, ICT Ezy 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.