Dan Dan - 27 days ago 16
Python Question

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.

Answer

@saua is right, and

str = str[:1].upper() + str[1:]

will work for any string

Comments