Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.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; 'python,': 0.02; 'subject:: [': 0.03; 'output': 0.04; 'objects,': 0.07; 'subject:question': 0.08; '(1,': 0.09; 'behave': 0.09; 'explanation': 0.09; 'mutable': 0.09; 'objects.': 0.09; 'tuple': 0.09; 'way:': 0.09; 'aug': 0.13; 'constants': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ids.': 0.16; 'nonetheless': 0.16; 'one-element': 0.16; 'parameters,': 0.16; 'time).': 0.16; 'string': 0.17; 'wrote:': 0.17; '>>>': 0.18; 'subject:] ': 0.19; 'parameters': 0.20; 'received:209.85.214.174': 0.21; 'header:In-Reply-To:1': 0.25; 'compiled': 0.27; 'message-id:@mail.gmail.com': 0.27; 'fri,': 0.30; 'lists': 0.31; 'subject:lists': 0.32; 'right?': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'possible': 0.37; 'two': 0.37; 'received:209': 0.37; 'things': 0.38; 'nothing': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'different': 0.63; 'more': 0.63; 'dealt': 0.91; 'angel': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=+FQHCCnlXbhDNEV/IxvW+pdi7geLQU4HnaWnrzuKHOY=; b=V75DY2yuYVla2KGlnQY17l6aVpkizLd2tE1DhxomyszpxgUyVkKdxwjH+CRthNlNBt 7eWWAI09zPvgx6QiCMx4TbwFU4mnspxZjMYE80DI/EkU9LlConpm50G4f2gXFFjZgTDX 82iydymhzBMVA1087++F0bl+OOX+4Y/mlcdcaAOv6c+WOlEkxnHuEh79pf6tsDUnYMUh TqEqvQU5jkkifS6H6CQyt5+s/JocRqdelPUeNt5yKimj92kCBKqP1VmHvDoSgdwgGvBa ciMaRLRKOaIojXVLP2aznsVci2INO7y44DfJahwTfLzIveYYqSAjpvVU40oACHt3Texi 0T0A== MIME-Version: 1.0 In-Reply-To: References: <39A401F0-12DD-464F-A0D1-639C56FA48A0@gmail.com> Date: Fri, 10 Aug 2012 20:37:24 +1000 Subject: Re: [newbie] A question about lists and strings 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344595047 news.xs4all.nl 6858 [2001:888:2000:d::a6]:55059 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26856 On Fri, Aug 10, 2012 at 8:12 PM, Mok-Kong Shen wrote: > Thanks for the explanation of the output obtained. But this means > nonetheless that parameters of types lists and strings are dealt with > in "inherently" (semantically) different ways by Python, right? It's nothing to do with parameters, but yes, lists are mutable and strings are immutable. A tuple will behave the same way a string does: >>> a (1, 2, 3, 4) >>> b=a >>> a+=5, # note that "5," is a one-element tuple >>> a (1, 2, 3, 4, 5) >>> b (1, 2, 3, 4) By the way: On Fri, Aug 10, 2012 at 8:07 PM, Dave Angel wrote: > But if you said c=651 and d=651, you'd have two > objects, and the two names would be bound to different objects, with > different ids. To be more accurate, you *may* have two different objects. It's possible for things to be optimized (eg with small numbers, or with constants compiled at the same time). ChrisA