[Tutor] capitalize() but only first letter

Erik Price eprice@ptc.com
Thu Feb 6 12:41:16 2003


Jeff Shannon wrote:

[...]

Thanks for the clarification, Jeff.

> As a minor additional (pun not intended) point, I have a personal 
> preference to avoid using + with strings because eventually, that's 
> going to lead to code that reads something like "1" + "2", which may 
> lead to expecting either a result of "12" or "3".

I changed my script to use the sprintf-style method, since it just 
"felt" more appropriate than using list.append().join().  It looks a lot 
beter now.

I'm still somewhat confused since I would think that the following tuple 
uses four throwaway objects (three strings and the tuple itself), but I 
can see that you don't add an "additional" intermediate string between 
each string element of the tuple when you use join().

    t = ("first", "second", "third")

> (Obviously, the real 
> result is "12", but if I scanned over that in the middle of a page of 
> unfamiliar code, I might not see the obvious... especially since, as I 
> understand it, that same code in Perl *would* yield 3!)

You're right, though it's because Perl doesn't use + for concat (it uses 
a dot, which is kind of a pain since most OO langs use that for dot 
notation of object and method calls, so Perl had to use an arrow (->), 
which is even uglier than normal Perl code).


Erik