Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!217.188.199.168.MISMATCH!takemy.news.telefonica.de!telefonica.de!newsfeed.xs4all.nl!newsfeed3a.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'explicitly': 0.05; 'assign': 0.07; '#include': 0.09; 'main()': 0.09; 'mentions': 0.09; 'objects,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'variables.': 0.09; 'python': 0.11; '[2,': 0.16; 'assumptions': 0.16; 'operator.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.18; 'pointed': 0.19; '>>>': 0.22; 'header:User- Agent:1': 0.23; 'looks': 0.24; 'shown': 0.26; 'header:X -Complaints-To:1': 0.27; "doesn't": 0.30; 'subject:list': 0.30; 'gcc': 0.31; 'trouble': 0.34; 'objects': 0.35; 'but': 0.35; 'similar': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'days': 0.60; 'ago.': 0.61; 'more': 0.64; 'different': 0.65; 'below:': 0.68; 'behavior': 0.77; 'analog': 0.84; 'confusion.': 0.84; 'implications': 0.84; 'lot,': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: list storing variables Date: Mon, 23 Feb 2015 19:41:23 +0100 Organization: None References: <54eb2357$0$3011$426a74cc@news.free.fr> <8761ascwt4.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd9e67.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 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: 67 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424716896 news.xs4all.nl 2962 [2001:888:2000:d::a6]:41486 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86253 Marko Rauhamaa wrote: > Peter Pearson : > >>>>>> a = 2; b = 5 >>>>>> Li = [a, b] >>>>>> Li >>> [2, 5] >>>>>> a=3 >>>>>> Li >>> [2, 5] >> >> [...] >> >> The word "variable" brings implications and assumptions that get >> people into trouble in Python. Python doesn't have variables. >> It has objects, and you can assign names to objects -- like sticky >> notes, as someone in this newsgroup helpfully pointed out long ago. >> >> This way of thinking is significantly different from the familiar >> "variable" mind-set of C, but looks similar enough to produce some >> confusion. For me, the sticky-note analogy helped a lot, and in a >> few days many things made more sense. > > It's no different in C: > > #include > > int main() > { > int a = 2, b = 5; > int Li[2] = { a, b }; > printf("%d %d\n", Li[0], Li[1]); > a = 3; > printf("%d %d\n", Li[0], Li[1]); > return 0; > } > > Outputs: > > 2 5 > 2 5 > > > Marko The OP explicitly mentions the & operator. There's no python analog to that and the behavior shown below: $ cat pointers.c #include int main() { int a = 2, b = 5; int * Li[2] = { &a, &b }; printf("%d %d\n", *Li[0], *Li[1]); a = 3; printf("%d %d\n", *Li[0], *Li[1]); return 0; } $ gcc pointers.c $ ./a.out 2 5 3 5