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:39:17 -0700 Lines: 35 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 7LoD0G4vPZS+1gdZ6N3KbQMW6G+g9x5QNHNnPzS3y0dg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'yet.': 0.03; 'subject:Python': 0.05; 'assignment': 0.07; 'assigning': 0.09; 'nameerror:': 0.09; 'left:': 0.16; 'received:209.85.213.176': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sense,': 0.16; 'subject:variable': 0.16; 'woud': 0.16; "{'foo':": 0.16; 'wrote:': 0.16; '>>>': 0.20; '2015': 0.20; '"",': 0.22; 'assign': 0.22; 'am,': 0.23; 'defined': 0.23; 'dec': 0.23; "haven't": 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'fri,': 0.27; 'right.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'errors.': 0.27; 'values': 0.28; 'traceback': 0.33; 'file': 0.34; 'received:google.com': 0.35; 'execution': 0.35; 'something': 0.35; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'no,': 0.38; 'received:209': 0.38; 'mean': 0.38; 'means': 0.39; 'goes': 0.39; 'to:addr:python.org': 0.40; 'to:name:python': 0.84 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=5xSFuwOC7Yf8Cs+g+RALnKxda0SHCbdoJgt3aByUtDA=; b=MRlIDMs9tauQNcEgdnL/ZUHuhiv7WHWN5sX5tA/uaFKrgVAA4hZn2AVCpTV3LJyIW5 oOahTPHiRqgY6Z1BMJcqeyO4I9ivOVUP3WT8Q9Rqc/NRxlJhqFt0kuIrF/2vBz1ykaV6 YuZQIyjJCjRo9qHqc58UVY0tEKbo1J1RZYo3WlMddM2o2FtatHHey12mlzHWzaYxszvi MMz5+HMFyNxMhfq4DRSyL6itEExj61mOCtrq3hKMiljQ3saiX9sHpU4IP6svFO4I9M6j Srcfq7go493f9/GWVbOjjNdgNdU+9TIzCrfBIsS3SY1mIB5NpUpVGWacqebBRnLt5UMa 2YSQ== X-Received: by 10.50.154.5 with SMTP id vk5mr5611281igb.85.1449851997208; Fri, 11 Dec 2015 08:39:57 -0800 (PST) In-Reply-To: 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:100271 On Fri, Dec 11, 2015 at 9:24 AM, Robin Koch 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 "", line 1, in NameError: name 'd' is not defined