Isupper() Method in Python
This article presented an in-depth guide on the “isupper()” method using numerous examples.
What is the “isupper()” Method in Python?
The “isupper()” method in Python is utilized to determine whether all characters/letters in a particular string are in capital letters/Upper case or not. If every character in the specified string is in uppercase, the function retrieves “True”, otherwise it retrieves “False”.
Syntax
In the above syntax:
- The “isupper()” method does not take any parameters.
- This method retrieves a boolean value indicating whether a given condition is “True” or “False”.
Example 1: Applying the “isupper()” Method to Determine if all the String Characters are in Uppercase
This example demonstrates the use of the “isupper()” method to determine if all characters in a given string are in uppercase:
str2 = "Java"
print(str1.isupper())
print(str2.isupper())
In the above example code:
- Create two strings: one containing all uppercase letters and the other containing a combination of uppercase and lowercase letters.
- After that, the “isupper()” method is utilized to determine/check if all the string characters are in uppercase.
- This method retrieves a boolean value of “True” if all letters/characters in the input string are in uppercase, and “False” if not.
Output
As seen, the corresponding boolean values are retrieved in accordance with the satisfied and unsatisfied conditions, respectively.
Example 2: Applying the “isupper()” Method to Check if Some Characters in a String are in Uppercase
This example code is used to check if some of the string characters are in uppercase:
str2 = "pYTHOn gUIDe"
print(str1.isupper())
print(str2.isupper())
In the above code block:
- The two strings containing a mix of uppercase and lowercase letters are initialized in the program.
- The “isupper()” method is utilized to check/determine if some string letters/characters are in uppercase.
- The “isupper()” method retrieves a boolean value of “True” if all characters in the string are uppercase letters and “False” if the string contains a combination of upper and lowercase letters.
Output
The input strings do not contain any uppercase letters.
Conclusion
The built-in method “isupper()” can be used to check if all the letters/characters in a string are in uppercase or lowercase or others. The “isupper()” method is a simple yet powerful method that can be used to check if a string is in uppercase or not and it is especially useful when dealing with user inputs or when validating data. This post offered a complete guide on Python’s “isupper()” method using numerous examples.
Source: linuxhint.com