python capitalize first letter only

If the first character is an integer, it will not capitalize the first letter.

>>> '2s'.capitalize()

If you want the functionality, strip off the digits, you can use '2'.isdigit() to check for each character.

>>> s = '123sa'
>>> for i, c in enumerate(s):
...     if not c.isdigit():
...         break
>>> s[:i] + s[i:].capitalize()

Leave a Comment