Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8221

Re: what happens inside?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <enalicho@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'wed,': 0.03; 'assign': 0.04; 'cant': 0.09; 'mutable': 0.09; 'object.': 0.09; 'tuple.': 0.09; 'pm,': 0.10; '>>>': 0.12; 'wrote:': 0.14; 'immutable': 0.16; 'methods,': 0.16; 'cc:addr:python-list': 0.17; 'object,': 0.19; 'received:74.125.82.44': 0.19; 'received:mail-ww0-f44.google.com': 0.19; 'header:In-Reply-To:1': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'pointed': 0.25; 'object': 0.26; 'message- id:@mail.gmail.com': 0.28; 'changing': 0.28; 'needed,': 0.29; 'subject:?': 0.29; 'affected': 0.29; 'cc:addr:python.org': 0.30; 'tuples': 0.30; 'changes': 0.30; 'change.': 0.32; 'pointing': 0.32; 'someone': 0.33; 'list': 0.33; 'points': 0.34; 'however,': 0.34; 'using': 0.35; 'actual': 0.36; 'received:google.com': 0.37; 'change': 0.37; 'element': 0.37; 'case': 0.37; 'received:74.125.82': 0.38; 'received:74.125': 0.38; 'but': 0.38; 'data': 0.38; 'subject:: ': 0.38; '[1,2]': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=YKalKGyKfCJup2eK0tKWuXjtB44LCVXyZvI3czOw5iI=; b=CW3zjvpvmBpZU8YrYSBApvhhmtlOXKBCCN6Kv6xVYioIiqA6F5WDDfJY1sowbe4gF5 KMBinW+tIU4YS6evKkZkd0wihRtLqEiajmRo4OjMMOKETHaipxyX0cM3gXKOI8H0R3LT lSLnFzCnAn0UAUTHW7f4z2QayRyY+w8e079bc=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=ABAh+MpJ+pM4th3YL44cThTC7+pBVFk1TkfhyKQoT1/YXCgB7EIdEblShkMzHYn1BI cPyYWzyVANUoQXc2Xljl2baPoYZNKTekcUYDJ8LWvZgLvmBXcGrNm41nlbwBpeFCnQGJ VwimGcz9E46PyglxzF/EzMXceAAbAPOXvc40k=
MIME-Version 1.0
In-Reply-To <BANLkTim5-pusEdT2Qhm-0NJtbazLJMvxXA@mail.gmail.com>
References <BANLkTim5-pusEdT2Qhm-0NJtbazLJMvxXA@mail.gmail.com>
From Noah Hall <enalicho@gmail.com>
Date Wed, 22 Jun 2011 16:58:50 +0100
Subject Re: what happens inside?
To Chetan Harjani <chetan.harjani@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.286.1308758352.1164.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 82.94.164.166
X-Trace 1308758352 news.xs4all.nl 49176 [::ffff:82.94.164.166]:33091
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:8221

Show key headers only | View raw


On Wed, Jun 22, 2011 at 4:45 PM, Chetan Harjani
<chetan.harjani@gmail.com> wrote:
> why tuples are immutable whereas list are mutable?
Because an immutable data type was needed, and a mutable type was also needed ;)

> why when we do x=y where y is a list and then change a element in x, y
> changes too( but the same is not the case when we change the whole value in
> x ), whereas, in tuples when we change x, y is not affected and also we cant
> change each individual element in tuple. Someone please clarify.

That's because y points to an object. When you assign x = y, you say
"assign name x to object that's also pointed to by name y". When you
change the list using list methods, you're changing the actual object.
Since x and y both point to the same object, they both change.
However, if you then assign y = [1], name y no longer points to the
original object. x still remains pointing to the original object.

>>> a = [1,2] # assign name a to object [1,2]
>>> b = a # assign name b to object referred to by name a
>>> b
[1, 2]
>>> a = [3,4] # assign name a to object [3,4]
>>> b
[1, 2]
>>> a
[3, 4]

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: what happens inside? Noah Hall <enalicho@gmail.com> - 2011-06-22 16:58 +0100

csiph-web