Python | String upper()
upper() method converts all lowercase characters in a string into uppercase characters and returns it
Syntax :
string.upper()
Parameters :
The
upper()method doesn’t take any parameters.
Returns :
returns a uppercased string of the given string
CODE 1: String with only alphabetic characters
# Python3 program to show the # working of upper() function text = 'geeKs For geEkS' print("Original String:") print(text) # upper() function to convert # string to upper_case print("\nConverted String:") print(text.upper()) |
Output :
Original String: geeKs For geEkS Converted String: GEEKS FOR GEEKS
CODE 2: String with alphanumeric characters
# Python3 program to show the # working of upper() function text = 'g3Ek5 f0r gE3K5' print("Original String:") print(text) # upper() function to convert # string to upper_case print("\nConverted String:") print(text.upper()) |
Output :
Original String: g3Ek5 f0r gE3K5 Converted String: G3EK5 F0R GE3K5
Application: One of the common application of upper() method is to check if the two strings are same or not
# Python3 program to show the # working of upper() function text1 = 'geeks fOr geeks' text2 = 'gEeKS fOR GeeKs' # Comparison of strings using # upper() method if(text1.upper() == text2.upper()): print("Strings are same") else: print("Strings are not same") |
Output:
Strings are same
Recommended Posts:
- Python String Methods | Set 1 (find, rfind, startwith, endwith, islower, isupper, lower, upper, swapcase & title)
- numpy string operations | upper() function
- Python - Extract Upper Case Characters
- Python | Pandas Series.str.lower(), upper() and title()
- isupper(), islower(), lower(), upper() in Python and their applications
- Python program to count upper and lower case characters without using inbuilt functions
- Python regex to find sequences of one upper case letter followed by lower case letters
- Python | Check if given string can be formed by concatenating string elements of list
- String slicing in Python to check if a string can become empty by recursive deletion
- Python | Merge Tuple String List values to String
- Python - Remove front K characters from each string in String List
- Python - Length of shortest string in string list
- Python | Delimited String List to String Matrix
- Python | Sorting string using order defined by another string
- Python | Check if string ends with any string in given list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

