Am 16.05.2015 um 21:20 schrieb C.D. Reimer:

Does python perform the dot operators from left to right or according to
a rule of order (i.e., multiplication/division before add/subtract)?

In this case, it does the only thing it can do:

title = slug.replace('-',' ').title()

is performed as

* take slug
* get its replace method
* call it and take the result
* get this result's title method
* call it and store its result into title.

OTOH,

title = slug.title().replace('-',' ')

is performed as

* take slug
* get its title method
* call it and take the result
* get this result's replace method
* call it and store its result into title.

Any other order would be unintuitive and just wrong.

The reason why the result is the same is because .title() title-cases letters after a space as well as after a '-'.

In other cases, it wouldn't do so, so you have to take care what you do.


Thomas
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to