Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1a.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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'assign': 0.07; 'assignment': 0.07; 'result,': 0.07; 'explanation': 0.09; 'cc:addr :python-list': 0.11; 'wrote': 0.14; 'attempted': 0.16; 'did,': 0.16; 'expected,': 0.16; 'index.': 0.16; 'least.': 0.16; 'operation,': 0.16; 'url:faq': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'trying': 0.19; 'thu,': 0.19; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'exists': 0.24; 'faq': 0.24; 'questions:': 0.24; 'looks': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'extension': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'on,': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'context.': 0.31; 'url:python': 0.33; 'not.': 0.33; 'point.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'entry': 0.36; 'url:org': 0.36; 'should': 0.36; 'half': 0.37; 'being': 0.38; 'though,': 0.39; 'then,': 0.60; 'url:3': 0.61; "you're": 0.61; 'first': 0.61; 'linked': 0.65; 'to:addr:gmail.com': 0.65; 'implications': 0.84; 'tricky': 0.84; 'ware': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=qCxqMrbEnj38tAIXv/bF8YgdevtvvACtvrusGcTILfE=; b=OG3ASBjlbX3PPeAXSFJJA/4cIazcOnGqiHoQxM/ohL4CYlYgKFxWuPH2dhT3W1x1gB PV8AUxOerlzDxsxTHNZnGmnUMrbC1zh6qyQaRSUDv99UFoCh/Hc+jzFbEk1XM0MdQeL7 r1LdjXZYszCocvPEFL/eHRvsEs0CTP7zQEAixWDkPArW2jBuveUCCFPTfqQMutbftbIl 2Du2s6Md505TXhYvtLP+wozEHvq0UCONyTucWZHDnvNL3+lWMW6ELfW2ACKjX/OfUUoE dygD8sBjhnTxI8o3nPxE/pgzkCeYw3P29xn01TzMaPbvdy25c5/ovovK6VBiI3pQ1vgw NnCg== X-Received: by 10.204.168.72 with SMTP id t8mr21146bky.115.1393519649996; Thu, 27 Feb 2014 08:47:29 -0800 (PST) MIME-Version: 1.0 Sender: zachary.ware@gmail.com In-Reply-To: References: From: Zachary Ware Date: Thu, 27 Feb 2014 10:47:09 -0600 X-Google-Sender-Auth: XaluY2zIsufYYSXT2g94tNjLqyY Subject: Re: Tuples and immutability To: Eric Jacoboni Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: "python-list@python.org" 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393519651 news.xs4all.nl 2962 [2001:888:2000:d::a6]:34409 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67158 On Thu, Feb 27, 2014 at 10:27 AM, Eric Jacoboni w= rote: > Le 27/02/2014 17:13, Zachary Ware a =C3=A9crit : >> >> You're not the first person to have this question :) >> >> http://docs.python.org/3/faq/programming.html#why-does-a-tuple-i-item-ra= ise-an-exception-when-the-addition-works >> > > Oh yes, i was aware of this explanation (thanks to Chris for his answer, > too)... and that's why i wrote "reasonable" :) > I know i should use append() or extend() and i understand the tricky > implications of +=3D in this context. But, imho, it's far from being a > intuitive result, to say the least. Well, once you understand what's actually going on, it's the result that you should expect. The FAQ entry I linked to exists to help people get to that point. To answer your specific questions: > But, then, why a_tuple is still modified? It is not. a_tuple is still "('spam', , 'eggs')", exactly the same before and after the attempted "a_tuple[1] +=3D [20]". The change is internal to . > I get a TypeError for an illegal operation, but this operation is still > completed? Half completed. The extension of happened as expected, but the assignment of to a_tuple[1] didn't. It looks like it did, though, because the assignment was just trying to assign the same object to the same index. --=20 Zach