Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90753 > unrolled thread

Re: Rule of order for dot operators?

Started byJoel Goldstick <joel.goldstick@gmail.com>
First post2015-05-16 15:33 -0400
Last post2015-05-16 15:33 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Rule of order for dot operators? Joel Goldstick <joel.goldstick@gmail.com> - 2015-05-16 15:33 -0400

#90753 — Re: Rule of order for dot operators?

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2015-05-16 15:33 -0400
SubjectRe: Rule of order for dot operators?
Message-ID<mailman.82.1431804831.17265.python-list@python.org>
On Sat, May 16, 2015 at 3:20 PM, C.D. Reimer <chris@cdreimer.com> wrote:
> Greetings,
>
> Noobie question regarding a single line of code that transforms a URL slug
> ("this-is-a-slug") into a title ("This Is A Slug").
>
> 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)?
>
> Thank you,
>
> Chris Reimer
> --
> https://mail.python.org/mailman/listinfo/python-list

>From left to right.  So in your first example it replaces - with
space, then capitalizes each word.
In your second example, it does the caps first, then gets rid of the dashes

-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web