In this tutorial, we’ll learn what Python string isupper() method is and how to properly use it. We’ll go through multiple Python code examples to understand how isupper() method works in Python.
Introduction: Python String isupper() Method
This isupper() method will return True if the string consists of uppercase alphabets and will return False, if atleast one alphabet is in lowercase format.
Syntax of isupper() Method
string.isupper()
- Python string isupper() method does not take any arguments.
- This method returns True if all the alphabets in a string are in uppercase format and returns False, if atleast one alphabet is in lowercase format or if the string is empty.
Example 1: Python String isupper() Method applied on a String
val='PYTHON PROGRAMMING' print(val.isupper()) print('PYTHON3 PROGRAMMING'.isupper()) print('PYTHON3_PROGRAMMING'.isupper()) print('PYTHON 3'.isupper()) print('PYTHON-3 IS @ PROGRAMMING LANGUAGE.'.isupper())
Output
True True True True True
Python string isupper() method return True as all the above specified strings has all their alphabets in uppercase format.
See below examples to see what isupper() method will return if we applied it on a string having lowercase alphabets as well.
print('PYTHON3 programming'.isupper()) print('PYTHON3_Program'.isupper()) print('Python 3'.isupper()) print('PYTHOn-3 IS @ ProgrammING LANGUAGE.'.isupper()) print(''.isupper()) // empty string
Output
False False False False False
Python string isupper() method return False as one or more alphabets in the above specified strings are in lowercase format.
Example 2: isupper() Method in Python If Else Condition
valStr='PYTHON IS A PROGRAMMING LANGUAGE.' if valStr.isupper() == True: print('The string is upper-cased') else: print('The string is not upper-cased')
Output
The string is upper-cased
Example 3: Python String isupper() Method Return Value
valStr='PYTHON PROGRAMMING WORLD' returnedVal=valStr.isupper() print(returnedVal)
Output
True
We can see that isupper() method return True as the above specified string has all its alphabets in uppercase format.
Conclusion
To conclude this tutorial, hope you now have a detailed practical understanding of how to properly use Python string isupper method. I’ll be looking forward to receive your feedback on this post. Thank you for reading it.