Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:: [': 0.03; 'function,': 0.07; 'subject:question': 0.08; 'assigning': 0.09; 'def': 0.10; 'aug': 0.13; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'one-element': 0.16; 'string': 0.17; 'wrote:': 0.17; 'string,': 0.17; '>>>': 0.18; 'subject:] ': 0.19; 'received:209.85.214.174': 0.21; 'modifying': 0.22; 'header :In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'chris': 0.28; 'pointer.': 0.29; 'probably': 0.29; 'fri,': 0.30; 'subject:lists': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'returning': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'really': 0.36; 'but': 0.36; 'level.': 0.36; 'level': 0.37; 'why': 0.37; 'received:209': 0.37; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'worth': 0.63; 'world': 0.63; 'wanting': 0.65 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=JOrohitDBjn0d66ldKpN28laJEE8ZEv/1ov3RaQhia8=; b=TIe4CnBZTBadw+aUI1oexI60X+OJBolpa51fDnIfHLm+rxqjDE1e/beYsvCT8kICFp CU83G/0p5R/NQaugUL2rgCmPySkD1GW7ZuPku0lqWGMdcKFwQ6vciYW9hu0xNaaN4etR dJIC3Oxz2yssk1bPJyAdbD9IMaBS3IFb6+cDlZYCy23d3PKvk8PYlmnL02Aiy7h9tfRZ ZTRPN5O+MFCNtSz6KTg4/PxwnTmYLG79wxt0DYru7yIuiTdqHMiogtwC0lGHBvbFJfLl h7Xvs3k8P1nVrhxIDC6sGXOT7LekJEeGjhZE8RO1GI60dM+kXUThMbaKkYqZuux+iBeG 1D+Q== MIME-Version: 1.0 In-Reply-To: References: Date: Fri, 10 Aug 2012 20:40:01 +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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344595204 news.xs4all.nl 6920 [2001:888:2000:d::a6]:57957 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26858 On Fri, Aug 10, 2012 at 8:31 PM, Mok-Kong Shen wrote: > This means there is no way of modifying a string at the top level > via a function, excepting through returning a new value and assigning > that to the string name at the top level. Please again correct me, if > I am wrong. Yes, but you can (ab)use a one-element list as a pointer. >>> foo=["Hello"] >>> def mutate(ptr): ptr[0]="World" >>> mutate(foo) >>> print(foo[0]) World But it's probably worth thinking about exactly why you're wanting to change that string, and what you're really looking to accomplish. There may well be a better way. Chris Angelico