Python String upper() – ItsMyCode

Python String upper() - ItsMyCode

Python String upper() method is a built-in function that converts all the lowercase characters into uppercase and returns it.

upper() Syntax

The syntax of upper() method is:


upper() Parameter

The upper() method doesn’t take any parameters.

upper() Return Value

The upper() method returns the uppercase of a given string. It converts all the lowercase characters in a string to uppercase.

If the String does not consist of any lowercase characters, it returns the original String.

Example 1: Convert a string to uppercase

The following program converts all the lowercase characters in a string to uppercase.

# Program to convert lowercase characters to uppercase
text= "ItsMYCode Coding Simplified"
text2="hello world"
print('Original String: ',text)
print('Original String: ',text2)

print('Uppercase String: ',text.upper())
print("Uppercase String: ", text2.upper())


Original String:  ItsMYCode Coding Simplified
Original String:  hello world
Uppercase String:  HELLO WORLD

Example 2: How upper() is used in a program?

If the string contains numeric/digits, the upper() method will return as is. Only the characters with lowercase will be converted to uppercase and returned.

Note: The same logic applies to even symbols and special characters. Apart from lowercase, none of the other characters will be converted. It will be returned as-is.

# Program to convert Alphanumeric characters to uppercase
text= "Its 2:00pm ist in India"
print('Original String: ',text)
print('Uppercase String: ',text.upper())


Original String:  Its 2:00pm ist in India
Uppercase String:  ITS 2:00PM IST IN INDIA

Example 3: How to check if two strings are same in Python

# Program to check the email and re-entered email is same or different
email= "[email protected]"
confirmemail="[email protected]"

if(email.upper() == confirmemail.upper()):
    print("Email Address are same")
    print("Email Address are not same")


Email Address are same

Source link

Leave a reply

Please enter your comment!
Please enter your name here