capitalize() NOT the same as var[0].upper _ var[1:]

James Mills prologic at shortcircuit.net.au
Tue Jun 8 14:40:30 EDT 2010


2010/6/9 Victor Subervi <victorsubervi at gmail.com>:
> Sorry, Dennis:
>
> var = 'colorsShort'
> var[0].upper + var[1:] = 'ColorsShort'
> var.capitalize() = 'Colorsshort'

"""
string.capitalize = capitalize(s)
    capitalize(s) -> string

    Return a copy of the string s with only its first character
    capitalized.
"""

The behavior you've demonstrated is "exactly" what the documentation
says the .capitalize() method does.

--James



More information about the Python-list mailing list