Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.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.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'assignment': 0.07; 'python': 0.11; 'ok...': 0.16; 'operation,': 0.16; 'tuple': 0.16; 'typeerror:': 0.16; 'url:faq': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'thu,': 0.19; 'feb': 0.22; 'cc:addr:gmail.com': 0.22; 'to:name:python-list@python.org': 0.22; 'question': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '"",': 0.31; '>>>>': 0.31; 'file': 0.32; 'url:python': 0.33; '(most': 0.33; 'problem': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'hi,': 0.36; 'url:org': 0.36; 'to:addr:python-list': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'then,': 0.60; 'url:3': 0.61; "you're": 0.61; 'first': 0.61; '30,': 0.65 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; bh=6buIi+oWhqkefZ87MwbmT8kPzaCLbBGBcnH2WNxYWFo=; b=DgCGgsYflEIzhAUWvtF4K+t17YYmgh4IzhNJk9SfsnecMWx64T7GHMKBMc3DGaKxJq 8ArLBO+EwVcw9j6o7mz4428OhEaNRdddGewNzEJ6bVIYAely8gSpT7U/5yb6/yjO95/K sqEaKnMznpIfi8LLKi/kfilMyKo/XyaEUWDoqJ6yL+YiIUrQsJmg1I7oXjpOfA9ZF99W 80ctOH9TZO5OZGJBMtT6n9ZhFaG8lMHJC50aSiwt9a0IpumrFvsvUUAsCzxRG0DY1aBr 7WCC3DdsvV8RNHQ1Z9tEt+9nsGO3aQA6L7wiLxmUFYCoEDhd8EFcsoEFSilMOXSljVx0 kWdw== X-Received: by 10.204.98.76 with SMTP id p12mr1907bkn.176.1393517630119; Thu, 27 Feb 2014 08:13:50 -0800 (PST) MIME-Version: 1.0 Sender: zachary.ware@gmail.com In-Reply-To: References: From: Zachary Ware Date: Thu, 27 Feb 2014 10:13:30 -0600 X-Google-Sender-Auth: cJkMs_I1P2gSfPn5J5W9TMDYbLY Subject: Re: Tuples and immutability To: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 Cc: Eric Jacoboni 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393517631 news.xs4all.nl 2871 [2001:888:2000:d::a6]:43021 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67152 On Thu, Feb 27, 2014 at 10:01 AM, Eric Jacoboni wrote: > Hi, > > I'm using Python 3.3 and i have a problem for which i've still not found > any reasonable explanation... > >>>> a_tuple = ("spam", [10, 30], "eggs") >>>> a_tuple[1] += [20] > Traceback (most recent call last): > File "", line 1, in > TypeError: 'tuple' object does not support item assignment > > Ok... I accept this message as += is a reassignment of a_tuple[1] and a > tuple is immutable... > > But, then, why a_tuple is still modified? > >>>> a_tuple > ('spam', [10, 30, 20], 'eggs') > > I get a TypeError for an illegal operation, but this operation is still > completed? You're not the first person to have this question :) http://docs.python.org/3/faq/programming.html#why-does-a-tuple-i-item-raise-an-exception-when-the-addition-works -- Zach