Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'integer,': 0.09; 'object.': 0.09; 'am,': 0.13; 'wrote:': 0.15; '(1,': 0.16; '(2,': 0.16; '[])': 0.16; 'curiosity,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'orientation;': 0.16; 'set;': 0.16; 'subject:behavior': 0.16; 'subject:example': 0.16; 'subject:set': 0.16; 'method.': 0.16; 'object,': 0.16; '>>>': 0.16; 'received:74.125.82.174': 0.19; 'received:mail- wy0-f174.google.com': 0.19; 'header:In-Reply-To:1': 0.22; 'message-id:@mail.gmail.com': 0.28; 'object': 0.30; 'sun,': 0.30; 'changes': 0.31; 'chris': 0.32; 'does': 0.32; 'to:addr:python- list': 0.34; 'calling': 0.34; 'difference': 0.34; 'regardless': 0.34; 'integer': 0.35; 'but': 0.37; 'received:google.com': 0.38; 'subject:: ': 0.38; 'received:74.125.82': 0.39; 'to:addr:python.org': 0.39; 'received:74.125': 0.40; 'saqib': 0.84; 'subject:class': 0.84; 'by.': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=dZ7snHFLO4EZPrFZXxixwWYPF9PbTU85PoEHINR/OD8=; b=h5nyJovcnzuaKNeAXL5fYvka5hPaQvyPftZpO7RtR0SF7NkjeoUD6GXXL1RIlhRKVq S1v8A6PtMbObi4bfdXGLR9YiyxHPIo0puIvb5s0NnskHHP9aaq8Ukv+lT4Lbo3oRbdel ExytXFCTtDh+FerpVLFtc+jeM9UmlKMccQOXY= MIME-Version: 1.0 In-Reply-To: <6441039f-f226-4632-8e74-2b6415bf914e@n28g2000vbs.googlegroups.com> References: <2dc52e22-5c0f-4e24-8197-df616db1a42c@u2g2000yqb.googlegroups.com> <6441039f-f226-4632-8e74-2b6415bf914e@n28g2000vbs.googlegroups.com> Date: Sun, 3 Jul 2011 10:46:02 +1000 Subject: Re: Inexplicable behavior in simple example of a set in a class From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1309653963 news.xs4all.nl 21756 [2001:888:2000:d::a6]:44644 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:8698 On Sun, Jul 3, 2011 at 8:23 AM, Saqib Ali wrote: > So just out of curiosity, why does it work as I had expected when the > member contains an integer, but not when the member contains a set? It's not integer vs set; it's the difference between rebinding and calling a method. It's nothing to do with object orientation; the same happens with ordinary variables: >>> a=b=1 >>> a,b (1, 1) >>> a=2 >>> a,b (2, 1) >>> c=d=[] >>> c,d ({}, []) >>> c.append("Test") >>> c,d (['Test'], ['Test']) But: >>> c=['Foobar'] >>> c,d (['Foobar'], ['Test']) When you do a=2 or c=['Foobar'], you're rebinding the name to a new object. But c.append() changes that object, so it changes it regardless of which name you look for it by. Chris Angelico