Python String upper() function transforms all lowercase characters into uppercase and returns an uppercase string. Strings are immutable, so the original string value remains unchanged.
The syntax of the method is: str.upper()
Key Points :
• Return Type: The function upper() returns the upper string of the string. All lowercase characters are translated to uppercase.
• Parametric values: No parameters are taken into the upper() function.
• If there are no lowercase characters, the actual string is restored.
• Because strings in Python are immutable, only a copy of the original string is returned.
• The original string does not change. A new variable name may be saved for the modified string.
Below is the python program to demonstrate the upper() function:
str = "The Best Learning Resource for Online Education"; print (str.upper())
When we run above the program, the outcome is as follows:
THE BEST LEARNING RESOURCE FOR ONLINE EDUCATION
We’ll be covering the following topics in this tutorial:
Python String upper(): Digits and Symbols
If any string consists of numbers, symbols, and letters, then the numbers and symbols are restored, while the letters are translated into uppercase. Let’s see the following snippet code:
str = "Lucky786" print(str.upper())
When we run above the program, the outcome is as follows:
LUCKY786
Python String upper(): To check if two string are same or not
In the illustration below, we can verify whether the two strings are the same as the support of the upper() function. Let’s see the provided snippet code:
# first string Str_first = "The Best Learning Resource For Online Education" # second string Str_Second = "THE BEST LEARNING RESOURCE FOR ONLINE EDUCATION" if(Str_first.upper() == Str_Second.upper()): print("Both Strings are Same.") else: print("Both Strings are not Same.")
When we run above the program, the outcome is as follows:
Both Strings are Same.
Note that the original string is unchanged when we call upper() on a string object. This method generates and returns a second string of uppercase characters.
Below are several other functions that we can use to work with string in Python 3