Dan Dan - 1 year ago 146
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 Source

@saua is right, and

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

will work for any string

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download