python String upper() Method
The upper() function converts all lowercase letters in a string to uppercase and returns. But do not deal with symbols and numbers.
How to formulate it like this:
string.upper()
Argument: The upper() function takes no argument.
return value: The upper() function returns a new string with uppercase letters from the original string
Example:
txt = "this is string example."
print(txt.upper())
The output will be:
THIS IS STRING EXAMPLE.
The following example shows how to display the original string and the converted string to uppercase via the upper() function
Example:
txt = "Learn Python with Ahmed Obaid"
print("Original String:")
print(txt)
# upper() function to convert
# string to upper_case
print("Converted String:")
print(txt.upper())
The output will be:
Original String:
Learn Python with Ahmed Obaid
Converted String:
LEARN PYTHON WITH AHMED OBAID
The upper() function can also be used to check whether two strings are the same
Example:
a = 'learn python with ahmed obaid'
b = 'Learn Python with Ahmed Obaid'
# Comparison of strings using
# upper() method
if (a.upper() == b.upper()):
print("Strings are same")
else:
print("Strings are not same")
The output will be:
Strings are same
External sources:
Built-in functions - official Python documentation
If you have any questions or concerns, leave them in the comments
Tags
Python Python String string methods python python string upper method
Share page
About author
Ahmed Obaid
Hello, I am Ahmed Obaid, an Egyptian Arabic programmer. I would like to put my experiences learning Python on this site So that it will be a reference for you and me as well.
Sign up to leave a comment