Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Antoon Pardon Newsgroups: comp.lang.python Subject: Re: Explaining names vs variables in Python Date: Wed, 2 Mar 2016 10:08:17 +0100 Lines: 41 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de FxpMUR1r+uctUXkngAA7HAIKQpwndQF3yCRLrQ1dWFWQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'received:134': 0.05; 'undefined': 0.07; 'objects.': 0.09; 'variables,': 0.09; 'python': 0.10; 'python.': 0.11; 'variables': 0.15; 'coincidence.': 0.16; 'dio': 0.16; 'lisp,': 0.16; 'received:ac.be': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'variations': 0.16; 'wrote:': 0.16; 'variable': 0.18; 'language': 0.19; 'names.': 0.22; 'variables.': 0.22; 'header:In- Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'behaviour': 0.29; 'consistency': 0.29; 'objects': 0.29; 'code': 0.30; 'received:be': 0.30; 'language.': 0.32; 'statement': 0.32; 'third': 0.33; 'true.': 0.33; 'similar': 0.33; 'except': 0.34; 'false': 0.35; 'according': 0.36; 'but': 0.36; 'there': 0.36; 'depends': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'being': 0.37; 'names': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'hello,': 0.40; 'behavior': 0.61; 'more': 0.63; 'pardon': 0.84; 'salvatore': 0.84 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AskOAPGs1laGuA9G/2dsb2JhbABchFMBvD2GEwKCDQEBAQEBAWWEaAEBAQMBI1UGCwsYAgIFFgsCAgkDAgECAUUTCAKIEwitYoslg3MBAQgCHnuFF4Q6hQGCNIE6BZcSgUKMIYkYhV6OTGKDZYkqAQEB User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.5.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 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:103848 On 02/03/2016 09:32, Salvatore DI DIO wrote: > Hello, > > I know Python does not have variables, but names. > Multiple names cant then be bound to the same objects. > > So this behavior Python has variables. They are just not the kind of variables you find in C and variations but more like variables in lisp, scheme and smalltalk. >>>> b = 234 >>>> v = 234 >>>> b is v > True > > according to the above that is ok No that is just a coincidence. A consequent of the particular implimentation, that has prepared a number of number objects beforehand. There is no guarantee in the language that the third statement above will produce True. > But where is the consistency ? if I try : > >>>> v = 890 >>>> w = 890 >>>> v is w > False > > It is a little difficult to explain this behavior to a newcommer in Python. This behaviour is undefined in the language. So there is nothing to explain except that it depends on implementation details. Any program that depends on two variable being the same or not the after similar code is wrong. -- Antoon Pardon