Python String isupper() method (original) (raw)
Last Updated : 02 Jan, 2025
isupper() method in Python checks if all the alphabetic characters in a string are uppercase. If the string contains at least one alphabetic character and all of them are uppercase, the method returns True
. Otherwise, it returns False
.
Let’s understand this with the help of an example:
Python `
s = "GEEKSFORGEEKS" print(s.isupper())
`
Explanation:
- The string ‘
s'
contains only uppercase alphabetic characters. - Therefore, the
isupper()
method returnsTrue
. - This method helps us verify that all characters intended to be uppercase are correctly formatted.
Table of Content
- Syntax of isupper() method
- Examples of isupper() method
- Frequently Asked Questions (FAQs) on issuper() method
Syntax of method
string.isupper()
Parameters
- The
isupper()
method does not take any parameters.
Return Type
- Returns
True
if all alphabetic characters in the string are uppercase. - Returns
False
if the string contains lowercase letters or non-alphabetic characters.
Examples of method
Checking a string with all uppercase letters
Let’s examine a case where the string is entirely uppercase, we can use this to validate input when uppercase formatting is required, such as for acronyms or constants.
Python `
s1 = "PYTHON" print(s1.isupper())
`
Explanation:
- The string
s1
is made up entirely of uppercase alphabetic characters. - The method returns
True
, confirming that all alphabetic characters ins1
are uppercase.
Checking a string with mixed case letters
This method is helpful when we want to ensure that no lowercase letters are present in a string.
Python `
s2 = "PyThOn" print(s2.isupper())
`
Explanation:
- The string
s2
contains both uppercase (P
,T
,O
) and lowercase (y
,h
,n
) characters. - As a result,
isupper()
returnsFalse
.
Checking a string with non-alphabetic characters
Let’s check how isupper()
behaves when the string contains numbers or special characters.
Python `
s3 = "123#@!" print(s3.isupper())
`
Explanation:
- The string
s3
contains only non-alphabetic characters (numbers and special symbols). - Since there are no uppercase alphabetic characters,
isupper()
returnsFalse
.
String with spaces and uppercase letters
This method is useful when validating input strings with uppercase letters and spaces, such as titles or banners.
Python `
s4 = "PYTHON IS FUN" print(s4.isupper())
`
Explanation:
- The string
s4
contains uppercase alphabetic characters and spaces. - Spaces are non-alphabetic characters and do not affect the result.
- The method returns
True
, confirming that all alphabetic characters ins4
are uppercase.
5. An empty string
This is useful when we want to ensure that we’re working with meaningful input before applying further processing.
Python `
s5 = "" print(s5.isupper())
`
Explanation:
- The string
s5
is empty and does not contain any characters. - The
isupper()
method returnsFalse
since there are no uppercase alphabetic characters to validate.