Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!cs.uu.nl!news0.firedrake.org!news.nosignal.org!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; 'skip:[ 20': 0.03; 'python': 0.09; '")': 0.09; '[1,': 0.09; 'below).': 0.09; 'def': 0.10; '2.7': 0.13; '(like': 0.15; 'assignment.': 0.16; 'appropriate': 0.20; 'variable': 0.20; 'changes': 0.20; 'assignment': 0.22; 'skip:[ 10': 0.26; '(see': 0.27; 'functions.': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'definition': 0.29; 'becomes': 0.30; 'function': 0.30; 'code': 0.31; 'print': 0.32; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'but': 0.36; 'thank': 0.36; 'received:209': 0.37; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'from:no real name:2**0': 0.60; 'you.': 0.61; 'subject:, ': 0.61; 'behavior': 0.64 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=o7QZGLz3l93eSXbT2kibxEdgoFn7dnMuL87Na6i/MrI=; b=jlPa8d8ikjbzCadfmuefZk0X9BoqV2vVGoaifYduDd+g1Jw6UcxDqdaNsfRzo1yr3E Qa+6m6jUxs3p/zRnMn7Ess7R4NxmbVcdFU6d9uD0Fa4A90bCcAVG1HwtKFCR3ploQA1+ +KQRAKyL2rmoCYqw9EGNBrgW0YWCVh8g1cuTerLucS/p/AzV0SicZVZHORvP5Zz4Q5A5 Kjg05LH/8VY34IRQdpUnF43muKqGydEEmK7LX6oQRCMUgO+j67zEvEAQuke+Dc72Bnk9 OAAdvYkjZQVZRHXPGWOPOX1Ev+s6JsM9gq6nfdIF7tDl8PUGnf+3+8DPVvsGQvhQJaSx NOUA== MIME-Version: 1.0 Date: Tue, 4 Dec 2012 14:55:44 +0400 Subject: scope, function, mutable From: gusarer@gmail.com To: Python-list@python.org Content-Type: multipart/alternative; boundary=14dae93408572eee8f04d004b5b7 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: 60 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1354618548 news.xs4all.nl 6918 [2001:888:2000:d::a6]:35219 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34214 --14dae93408572eee8f04d004b5b7 Content-Type: text/plain; charset=ISO-8859-1 Hi, What is the appropriate definition for the following behavior in Python 2.7 (see code below). Both functions have assignment in it (like "x = ") so I assume, that x is a local variable in both functions. Also I thought this rule doesn't depend on WHERE in this function we find the assignment. But in both functions x becomes local variable only AFTER assignment, so in f2 x[1] = 99 changes the global varialble (btw, x[3] = 99 doesn't). def f1(x): x = [44] + x[1:] x[1] = 99 def f2(x): x[1] = 99 x = [44] + x[1:] x[3] = 99 t = [1,2,3,4,5,6,7] f1(t) print t # [1, 2, 3, 4, 5, 6, 7] t = [1,2,3,4,5,6,7] f2(t) print t # [1, 99, 3, 4, 5, 6, 7] Thank you. Roman Gusarev. --14dae93408572eee8f04d004b5b7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi,

What is the appropriate definition for the following= behavior in Python 2.7 (see code below).
Both functions have ass= ignment in it (like "x =3D ") so I assume, that x is a local vari= able in both functions.
Also I thought this rule doesn't depend on WHERE in this function = we find the assignment.

But in both functions x be= comes local variable only AFTER assignment, so in f2 x[1] =3D 99 changes th= e global varialble (btw, x[3] =3D 99 doesn't).

def f1(x):
=A0 =A0 x =3D [44] + x[1:]
=A0 =A0 x[1] =3D 99

def f2(x):
= =A0 =A0 x[1] =3D 99
=A0 =A0 x =3D [44] + x[1:]
=A0 =A0 = x[3] =3D 99

t =3D [1,2,3,4,5,6,7]
f1(t)
print t =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#=A0[1, 2, 3, 4, 5, 6, = 7]
t =3D [1,2,3,4,5,6,7]
f2(t)
print t=A0=A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#=A0[1, 99, 3, 4, 5, 6, = 7]

Thank you.

Roman Gusarev= .
--14dae93408572eee8f04d004b5b7--