What is the Python equivalent of Perl's ucfirst() or s///e?
If what you are interested in is upcasing every first character and lower casing the rest (not exactly what the OP is asking for), this is much cleaner:
string.title()
How about:
s = "i'm Brian, and so's my wife!"
print s[0].upper() + s[1:]
The output is:
I'm Brian, and so's my wife!
Just use string slicing:
s[0].upper() + s[1:]
Note that strings are immutable; this, just like capitalize()
, returns a new string.