Python Convert String to Uppercase
In this post, you will learn how to convert a string to uppercase. Python provides in-built methods to convert strings to uppercase.
The upper() method of Python converts all letters or characters of a string from lowercase to uppercase. The syntax is -
string.upper()
The upper() method doesn't take any parameters. It returns the uppercase string from the given string.
Python Convert a string to uppercase
str1 = "welcome to etutorialspoint!"
print(str1.upper())
str2 = "best! educational resources 4432"
print(str2.upper())
Output of the above code:
WELCOME TO ETUTORIALSPOINT!
BEST! EDUCATIONAL RESOURCES 4432
Use of upper() to check string equality
# Python program
# to compare strings
str1 = 'etutorialspoint - educational resources'
str2 = 'etutorialsPOINT - EducaTionAL ResouRCeS'
# Comparison of strings using
# upper() method
if(str1.upper() == str2.upper()):
print("Both strings are same.")
else:
print("Both strings are not same.")
Output of the above code-
Both strings are same.
Related Articles
Convert Python list to numpy arrayConvert string to list Python
Python program to list even and odd numbers of a list
Python loop through list
Sort list in descending order Python
Convert array to list Python
Python take screenshot of specific window
Web scraping Python BeautifulSoup
Check if two strings are anagrams Python
Python program to add two numbers
Print new line python
Python for loop index
Convert List to Dataframe Python
numpy random choice
Dictionary inside list python
Check if list is empty Python
Python raise keyword
Python program to get the largest number from a list
Python program to map two lists into a dictionary