Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90818
| Date | 2015-05-19 08:29 +1000 |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Subject | Re: Rule of order for dot operators? |
| References | <55579886.3010001@cdreimer.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.118.1431989304.17265.python-list@python.org> (permalink) |
On 16May2015 12:20, C.D. Reimer <chris@cdreimer.com> 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 <cs@zip.com.au>
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Rule of order for dot operators? Cameron Simpson <cs@zip.com.au> - 2015-05-19 08:29 +1000
Re: Rule of order for dot operators? Rustom Mody <rustompmody@gmail.com> - 2015-05-18 18:32 -0700
Re: Rule of order for dot operators? Ron Adam <ron3200@gmail.com> - 2015-05-18 22:43 -0400
Re: Rule of order for dot operators? Chris Angelico <rosuav@gmail.com> - 2015-05-19 16:25 +1000
Re: Rule of order for dot operators? Ron Adam <ron3200@gmail.com> - 2015-05-19 14:02 -0400
Re: Rule of order for dot operators? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-06-08 11:21 +0000
Re: Rule of order for dot operators? Steven D'Aprano <steve@pearwood.info> - 2015-06-08 23:06 +1000
csiph-web