Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'cheers': 0.12; 'assume': 0.14; 'received:141': 0.14; '(1,': 0.16; '(note': 0.16; '3.0)': 0.16; 'chris,': 0.16; 'elements).': 0.16; 'elements,': 0.16; 'equal.': 0.16; 'immutability': 0.16; 'implies': 0.16; 'mutability': 0.16; 'objects.': 0.16; 'other,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'tuples,': 0.16; 'so.': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'seems': 0.21; 'separate': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'paul': 0.24; '2010,': 0.27; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'dec': 0.30; "i'm": 0.30; 'apparently': 0.31; 'tuples': 0.31; 'another': 0.32; "can't": 0.35; 'definition': 0.35; 'equal': 0.35; 'but': 0.35; 'false': 0.36; 'doing': 0.36; 'thanks': 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'from:charset:utf-8': 0.61; 'more': 0.64; 'subject:good': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: =?UTF-8?B?UGF1bCBLw7ZsbGU=?= Subject: Re: Mutable objects inside tuples - good or bad? Date: Mon, 07 Apr 2014 21:46:37 +0200 References: <89df32f9-c8ae-4b7b-bfc4-01c574aabcae@googlegroups.com> <53410185.6050304@islandtraining.com> <5342C3AD.9080707@subsignal.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: canon.lpg.tu-cottbus.de User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396900024 news.xs4all.nl 2944 [2001:888:2000:d::a6]:38426 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69819 Am 07.04.2014 17:44, schrieb Chris Angelico: > On Tue, Apr 8, 2014 at 1:26 AM, Paul Kölle wrote: >> It seems a tuple's immutability is debatable, or is this another instance of >> the small-integer-reuse-implementation-detail-artifact? >> >> Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) >> [GCC 4.4.5] on linux2 >> >> Type "help", "copyright", "credits" or "license" for more information. >>>>> a = ([1,2],[3,4]) >>>>> b = a >>>>> a is b >> True >>>>> a == b >> True >>>>> c = (1,2,3) >>>>> d = (1,2,3) >>>>> c is d >> False >>>>> c == d >> True > > That's nothing to do with mutability or reuse. With a and b, you > assigned one to be the same as the other, so they are by definition > identical (and equal; tuples assume that identity implies equality, > even though that may not be true of their elements). With c and d, you > assigned separate tuples, so they're allowed to be separate objects. > I'm not sure if they're allowed to be constant-folded, but CPython > apparently isn't doing so. They are still equal, though; they contain > equal elements, ergo they are equal. (Note that (1, 2, 3) and (1.0, > 2.0, 3.0) are equal, but they obviously can't be identical any more > than "1 is 1.0" can ever be True.) > > ChrisA > Thanks Chris, stupid error indeed ;) cheers Paul