How to Convert First Letter Capitalize in Python?

Nov 07, 2022

.

Admin

How to Convert First Letter Capitalize in Python?

Hi Dev,

I will explain step by step tutorial how to convert first letter capitalize in python. We will use python list convert into capitalize title example. This article will give you simple example of convert list to title case python. This tutorial will give you simple example of python list convert to title case.

There are many ways to convert list elements to capitalize first letter in python. i will give you two examples using for loop with title() to convert list data to capitalize first letter. so let's see the below examples.

so let's see following examples with output:

Example 1:


main.py

myList = ['one', 'two', 'three']

# Convert List Value into capitalize

for i in range(len(myList)):

myList[i] = myList[i].title()

print(myList)

Output:

['One', 'Two', 'Three']

Example 2:

main.py

myList = ['one', 'two', 'three']

# Convert List Value into capitalize

newList = [x.title() for x in myList]

print(newList)

Output:

['One', 'Two', 'Three']

#Python