In article <mailman.118.1431989304.17265.python-l...@python.org>, Cameron Simpson <c...@zip.com.au> wrote: >On 16May2015 12:20, C.D. Reimer <ch...@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".
Why is "slug.title" a valid decomposition of the total string> (Or is it?) What is the ()-brackets doing? Does it force the execution of title, which gives something to be dotted onto slug etc. See below. > >"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. I interpreted the question as about the associative of the dot operator. title = slug.title().replace('-',' ') Does that mean title = slug.( title().replace('-',' ') ) or title = ( slug.( title()) .replace('-',' ') or is it even <slot>.<slot>.<slot> a ternary operator with special syntax like we have in <slot> <= <slot> <= <slot> lately. It seems to me that you presuppose the answer. > >Cheers, >Cameron Simpson <c...@zip.com.au> -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst -- https://mail.python.org/mailman/listinfo/python-list