Capitalize a string
Does anyone know of a really simple way of capitalizing just the first letter of a string, regardless of the capitalization of the rest of the string?
For example:
asimpletest -> Asimpletest
aSimpleTest -> ASimpleTest
I would like to be able to do all string lengths as well.
>>> b = "my name"
>>> b.capitalize()
'My name'
>>> b.title()
'My Name'
@saua is right, and
s = s[:1].upper() + s[1:]
will work for any string.
What about your_string.title()
?
e.g. "banana".title() -> Banana