how to change the case of first letter of a string?

yyyy picture yyyy · Nov 19, 2010 · Viewed 37.2k times · Source
s = ['my', 'name']

I want to change the 1st letter of each element in to Upper Case.

s = ['My', 'Name']

Answer

Per Mejdal Rasmussen picture Per Mejdal Rasmussen · Nov 23, 2012

Both .capitalize() and .title(), changes the other letters in the string to lower case.

Here is a simple function that only changes the first letter to upper case, and leaves the rest unchanged.

def upcase_first_letter(s):
    return s[0].upper() + s[1:]