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 lowercasestring = 'ALL UPPER';print(string.isupper())# False - because string has lowercase character - rstring = 'LOWEr';print(string.isupper())# False - because no alphabetical character presentstring = '10';print(string.isupper())# True - because one alphabetical character present and that character is in upper casestring = '12B';print(string.isupper())# False - because one alphabetical character present and that character is not lower casestring = '12b';print(string.isupper())
In the above code, we call the isupper method:
-
For the string
ALL UPPER, theisupperwill returnTruebecause all the characters of the string are uppercase letters. -
For the string
LOWEr, theisupperwill returnFalsebecause the string contains one lowercase letter (r). -
For the string
10, theisupperwill returnFalsebecause the string contains no alphabetical letter. -
For the string
12B, theisupperwill returnTruebecause the string has one alphabetical character and that character is in uppercase. -
For the string
12b, theisupperwill returnFalsebecause the string has one lowercase character.