Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'assignment': 0.07; 'differently': 0.07; 'modified': 0.07; 'assigning': 0.09; 'augmented': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'similar,': 0.09; 'target,': 0.09; 'python': 0.11; 'language.': 0.14; 'windows': 0.15; "'+'": 0.16; 'behave': 0.16; 'effect.': 0.16; 'in-place,': 0.16; 'mutable': 0.16; 'once.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'rewritten': 0.16; 'subject:operators': 0.16; 'url:py': 0.16; 'subject:python': 0.16; 'attach': 0.16; 'language': 0.16; 'wrote:': 0.18; 'module': 0.19; 'possible,': 0.19; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'instead.': 0.24; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'url:bugs': 0.29; 'subject:list': 0.30; "d'aprano": 0.31; 'object.': 0.31; 'operators': 0.31; 'steven': 0.31; 'url:python': 0.33; 'actual': 0.34; 'problem': 0.35; 'except': 0.35; 'equal': 0.35; 'but': 0.35; 'module.': 0.36; 'url:org': 0.36; 'list': 0.37; 'server': 0.38; 'version,': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'explain': 0.39; 'delete': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'expression': 0.60; 'new': 0.61; 'skip:* 10': 0.61; 'our': 0.64; 'charset:windows-1252': 0.65; 'archana': 0.84; 'url:reference': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: FW: Unexpexted behaviot of python operators on list Date: Tue, 25 Nov 2014 12:20:26 +0000 References: <54746a98$0$12990$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 5.80.128.193 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: <54746a98$0$12990$c3e8da3$5496439d@news.astraweb.com> 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: 57 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416918045 news.xs4all.nl 2841 [2001:888:2000:d::a6]:44647 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81502 On 25/11/2014 11:40, Steven D'Aprano wrote: > PANDEY2 Archana (MORPHO) wrote: > >> Hello >> >> I hereby would like to share the problem I have found regarding python >> list implementation:- >> >> As per python documentation python list is mutable data object. >> >> That problem I found with the list is that is behaves differently when we >> use '+=' and '+' '=' operators separately. For example- >> a=a+1 and a +=1 both behave in same way for all data types except python >> list > > `a += b` is only *approximately* the same as `a = a+b`. The documentation > says: > > An augmented assignment expression like x += 1 can be rewritten as x = x + 1 > to achieve a similar, but not exactly equal effect. In the augmented > version, x is only evaluated once. Also, when possible, the actual > operation is performed in-place, meaning that rather than creating a new > object and assigning that to the target, the old object is modified > instead. > > https://docs.python.org/2/reference/simple_stmts.html#augmented-assignment-statements > > >> Please find the attached module and execute it on windows python32, See >> the difference in output. > > I cannot see the attached module. Did you forget to attach it, or did your > mail server delete it? > http://bugs.python.org/file37269/Operator_bug_python.py a=[1,2,3] b=a b+=[4,5] print(a) print(b) x=[1,2,3] y=x y=y+[4,5] print(x) print(y) I know that you can explain it better than I can :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence