What is string.isupper in Python?

The isupper method will return True if all the alphabetical characters present in the string are in uppercase. If any character of the string is in lowercase, or no alphabetical character is present in the string, then False is returned.

Syntax

string.isupper()

Return value

True:

  • If all the characters of the string are uppercase.

False in any one of the below cases:

  • If any character of the string is lowercase.

  • If no alphabetical character is present in the string.

# True - because all characters are lowercase
string = 'ALL UPPER';
print(string.isupper())
# False - because string has lowercase character - r
string = 'LOWEr';
print(string.isupper())
# False - because no alphabetical character present
string = '10';
print(string.isupper())
# True - because one alphabetical character present and that character is in upper case
string = '12B';
print(string.isupper())
# False - because one alphabetical character present and that character is not lower case
string = '12b';
print(string.isupper())

In the above code, we call the isupper method:

  • For the string ALL UPPER, the isupper will return True because all the characters of the string are uppercase letters.

  • For the string LOWEr, the isupper will return False because the string contains one lowercase letter (r).

  • For the string 10, the isupper will return False because the string contains no alphabetical letter.

  • For the string 12B, the isupper will return True because the string has one alphabetical character and that character is in uppercase.

  • For the string 12b, the isupper will return False because the string has one lowercase character.

Free Resources