Python capitalize the first letter of every word in the list | Example code

Use Python capitalize() method to capitalize every first letter of a word in the list. You have to also use for loop to iterate through the list.

str.capitalize()

Example How tocapitalize the first letter of every word in the list

Python simple code.

list1 = ["Hello", "how", "are", "you"]

for i in range(len(list1)):
    list1[i] = list1[i].capitalize()

print(list1)

Output:

Python capitalize the first letter of every word in the list

Another example

You can also use the python string title method with the same process.

list1 = ["Hello", "how", "are", "you"]

for i in range(len(list1)):
    list1[i] = list1[i].title()

print(list1)

Output: [‘Hello’, ‘How’, ‘Are’, ‘You’]

Do comment if you have any doubts and suggestions on this python list topic.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.