Python Convert List to Uppercase Example

Published On: 21/11/2022 | Category: Python


Hi Guys,

Here, I will show you how to works python convert list values to uppercase. this example will help you python convert list to uppercase example. step by step explain convert list to uppercase python. We will look at example of convert list elements to uppercase python. you will do the following things for convert list data to uppercase python.

In Python, there are numerous ways to change the case of list elements. I'll give you two examples of how to convert list data to uppercase using a for loop and upper(). So let's look at the examples below.

So let's see bellow example:

Example 1:

main.py
myList = ['One', 'two', 'Three']
  
# Convert List Value into uppercase
for i in range(len(myList)):
    myList[i] = myList[i].upper()
  
print(myList)
Output
['ONE', 'TWO', 'THREE']

Example 2:

main.py
myList = ['One', 'two', 'Three']
  
# Convert List Value into uppercase
newList = [x.upper() for x in myList]
  
print(newList)
Output
['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']

Example 3:

main.py
myString = "One,Two,Three,Four,Five"
  
# Convert String into List
newList = myString.split(",")
  
print(newList)
Output
['ONE', 'TWO', 'THREE']

It will help you....

Happy Pythonic Coding!