s = ['my', 'name']
I want to change the 1st letter of each element in to Upper Case.
s = ['My', 'Name']
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:]
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']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With