how to change the case of first letter of a string?
You can use the capitalize() method:
s = ['my', 'name']s = [item.capitalize() for item in s]print s # print(s) in Python 3
This will print:
['My', 'Name']
You can use 'my'.title()
which will return 'My'
.
To get over the complete list, simply map over it like this:
>>> map(lambda x: x.title(), s)['My', 'Name']
Actually, .title()
makes all words start with uppercase. If you want to strictly limit it the first letter, use capitalize()
instead. (This makes a difference for example in 'this word' being changed to either This Word
or This word
)