Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin.stu.neva.ru!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'string': 0.09; 'second.': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'itself.': 0.14; 'question.': 0.14; '>does': 0.16; '>to': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'simpson': 0.16; 'subject:operators': 0.16; 'titlecased': 0.16; 'wrote:': 0.18; 'example': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'string,': 0.24; 'switched': 0.24; 'cheers,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; "i've": 0.25; 'second': 0.26; 'skip:" 20': 0.27; 'header:In-Reply- To:1': 0.27; 'character': 0.29; 'asks': 0.31; 'operators': 0.31; 'second,': 0.31; 'not.': 0.33; 'version': 0.36; 'returning': 0.36; 'skip:> 10': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; '(i.e.,': 0.38; 'needed': 0.38; 'according': 0.40; 'around.': 0.60; 'expression': 0.60; 'new': 0.61; 'first': 0.61; 'content- disposition:inline': 0.62; 'anything.': 0.68; 'received:61': 0.74; 'mindset': 0.84; 'received:110': 0.96 X-Authentication-Info: Submitted using ID cskk@bigpond.com X-Authority-Analysis: v=2.0 cv=XNWyuHdE c=1 sm=1 a=KojQDM9EVEEjmP0UVe3/xQ==:17 a=yEdEr6MRgwAA:10 a=kj9zAlcOel0A:10 a=vrnE16BAAAAA:8 a=ZtCCktOnAAAA:8 a=h1PgugrvaO0A:10 a=qz9X1BTqAAAA:8 a=0pTO3-LQDI2yC4-yZ8MA:9 a=CjuIK1q_8ugA:10 a=KojQDM9EVEEjmP0UVe3/xQ==:117 Date: Tue, 19 May 2015 08:29:50 +1000 From: Cameron Simpson To: "C.D. Reimer" Cc: python-list@python.org Subject: Re: Rule of order for dot operators? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <55579886.3010001@cdreimer.com> User-Agent: Mutt/1.5.23 (2014-03-12) References: <55579886.3010001@cdreimer.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431989304 news.xs4all.nl 2874 [2001:888:2000:d::a6]:46556 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90818 On 16May2015 12:20, C.D. Reimer wrote: >title = slug.replace('-',' ').title() >This line also works if I switched the dot operators around. >title = slug.title().replace('-',' ') > >I'm reading the first example as character replacement first and title >capitalization second, and the second example as title capitalization >first and character replacement second. > >Does python perform the dot operators from left to right or according >to a rule of order (i.e., multiplication/division before add/subtract)? I've been thinking about the mindset that asks this question. I think the reason you needed to ask it was that you were thinking in terms of each .foo() operation acting on the original "slug". They do not. "slug" is an expression returning, of course, itself. "slug.title()" is an expression returning a new string which is a titlecased version of "slug". "slug.title().replace(...)" is an expression which _operates on_ that new string, _not_ on "slug". In particular, each .foo() need not return a string - it might return anything, and the following .bah() will work on that anything. Cheers, Cameron Simpson