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!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; 'subject:: [': 0.03; 'parameter': 0.07; 'subject:question': 0.08; 'arguments,': 0.09; 'follows.': 0.09; 'happens.': 0.09; 'mess': 0.09; 'received:mail- lpp01m010-f46.google.com': 0.09; 'str,': 0.09; 'cc:addr:python- list': 0.10; 'def': 0.10; 'anyway': 0.11; 'advance.': 0.15; '"+="': 0.16; 'cause.': 0.16; 'concatenated': 0.16; 'mutated': 0.16; 'string': 0.17; 'creates': 0.18; 'subject:] ': 0.19; 'earlier': 0.21; 'x-mailer:apple mail (2.1084)': 0.22; 'statement': 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'question': 0.27; "doesn't": 0.28; 'lines': 0.28; 'prints': 0.29; 'str': 0.29; 'url:mailman': 0.29; 'received:209.85.215.46': 0.30; 'returned': 0.30; 'function': 0.30; 'url:python': 0.32; 'subject:lists': 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'function.': 0.33; "can't": 0.34; 'skip:- 50': 0.34; 'received:google.com': 0.34; 'thanks': 0.34; 'list': 0.35; 'expected': 0.35; 'similar': 0.35; 'received:209.85': 0.35; 'list.': 0.35; 'message-id:@gmail.com': 0.36; 'url:org': 0.36; 'anything': 0.36; 'should': 0.36; 'two': 0.37; 'why': 0.37; 'passed': 0.37; 'received:209': 0.37; 'nothing': 0.38; 'takes': 0.39; 'called': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'url:mail': 0.40; 'your': 0.60; 'header:Message-Id:1': 0.62; 'more': 0.63; 'manner': 0.74; 'received:ru': 0.81; 'str.': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; bh=JIktbKiZF9xZpEUUDF9rOekOinIUcaNVkwzhAlBAMy8=; b=CFzQGGRYW2zOIZwSTNLedjjgzDqoG0YxYDdlL2Pjuo/0zI3RvnZKsv6tCrXi9VUl6C IK1n8oVHJAxdxzbWPvIu7SNrlNipFn7/gG9FoCGKIp8YeAlJw2NQojDZU8XK5c7CBkvG iaxeh0e2NbyRzzBFBVjL/F8ecWkBrTUKE1Stfoxy3w98GkP0vTOBjM4cleR5La0vHNKX NdO80mh4XBPEVv8rxGyAUq7NMlEdia8y6QhJerp8gxI2sdtoGYRi1uL4h/odlT4Jw3CG gom81orHpiW7wEwlLfICL8EoM6qs7Ly/sQ3lCm7NkfKUhsSDcspDH5NLTU9lyJnZIHUA iLpg== Subject: Re: [newbie] A question about lists and strings Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=koi8-r From: Roman Vashkevich In-Reply-To: <39A401F0-12DD-464F-A0D1-639C56FA48A0@gmail.com> Date: Fri, 10 Aug 2012 13:48:14 +0400 Content-Transfer-Encoding: quoted-printable References: <39A401F0-12DD-464F-A0D1-639C56FA48A0@gmail.com> To: Roman Vashkevich X-Mailer: Apple Mail (2.1084) Cc: python-list@python.org, Mok-Kong Shen 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: 56 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344592099 news.xs4all.nl 6936 [2001:888:2000:d::a6]:33163 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26851 10.08.2012, =D7 13:28, Roman Vashkevich =CE=C1=D0=C9=D3=C1=CC(=C1): > 10.08.2012, =D7 13:19, Mok-Kong Shen =CE=C1=D0=C9=D3=C1=CC(=C1): >=20 >>=20 >> In an earlier question about lists, I was told about the issue of >> creation of local names in a function. However, I still can't >> understand why the program below outputs: >>=20 >> [999] sss >> [999] >>=20 >> and not two identical lines of output. For both operators "+=3D" = should >> anyway work in similar manner in the function xx in my view. >>=20 >> Thanks for your help in advance. >>=20 >> M. K. Shen >>=20 >> ---------------------------------------------------------- >>=20 >> def xx(list,str): >> list+=3D[999] >> str+=3D"sss" >>=20 >> lista=3D[] >> stra=3D"" >> lista+=3D[999] >> stra+=3D"sss" >> print(lista,stra) >>=20 >> listb=3D[] >> strb=3D"" >> xx(listb,strb) >> print(listb,strb) >> --=20 >> http://mail.python.org/mailman/listinfo/python-list >=20 > It seems like your xx() function doesn't return local str parameter = and prints the global empty str, whereas it mutates the global list. >=20 > Roman Excuse me for the mess I just did in my message:) The function doesn't print anything of cause. It takes list by reference = and creates a new local str. When it's called with listb and strb arguments, listb is passed by = reference and mutated. A string "sss" is concatenated with an empty = local str. Nothing more happens. Since local str is not returned by = xx(), it can not be expected to be printed out in the statement that = follows. What is printed out in the print statement is the mutated listb = and the global strb. RV=