English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The string.upper() method converts all lowercase letters in the string to uppercase and returns it.
The syntax of the upper() method is:
string.upper()
The upper() method does not take any parameters.
The upper() method returns the uppercase string from the given string. It converts all lowercase letters to uppercase.
If there are no lowercase letters, return the original string.
# Example string string = "this should be uppercase!" print(string.upper()) # String with numbers # Convert all letters to uppercase string = "Th!s Sh0uLd B3 uPp3rCas3!" print(string.upper())
When running the program, the output is:
THIS SHOULD BE UPPERCASE! TH!S SH0ULD B3 UPP3RCAS3!
# First string firstString = "python is awesome!" # Second string secondString = "PyThOn Is AwEsOmE!" if(firstString.upper() == secondString.upper()): print("The strings are the same.") else: print("The strings are different.")
When running the program, the output is:
The strings are the same.
Note:If you want to convert to a lowercase string, please uselower()You can also useswapcase()Swap lowercase and uppercase letters.