A Python string is a collection of characters surrounded by single, double, or triple quotes. The computer does not understand the characters; instead, it stores the manipulated character as a combination of 0’s and 1’s internally.
In this article we are going to discuss about isupper() method
String isupper() method in Python
- isupper() method
- Checking if given string is an uppercase or not
- Checking if given number string is an uppercase or not
- Checking if given string containing letters and numbers an uppercase or not
- Checking if given character is in uppercase or not
1)isupper() method
If all of the characters are in upper case, the isupper() method returns True otherwise, it returns False.
Only alphabet characters are checked, not numbers, symbols, or spaces.
Syntax:
given_string.isupper()
Parameters:
No parameters are passed
Return:
If all cased characters in the string are uppercase and there is at least one cased character, this method returns true; otherwise, it returns false.
Examples:
2)Checking if given string is an uppercase or not
Using the isuuper() function, we can determine whether a string is uppercase or lowercase. If all of the string characters are upper case, the function isupper() returns True.
Below is the implementation:
# given string string = "BTECHGEEKS" # determining whether the given string is uppercase if(string.isupper()): print("Given string is in uppercase") else: print("Given string is not in uppercase")
Output:
Given string is in uppercase
EX-2)
# given string string = "Btechgeeks" # determining whether the given string is uppercase if(string.isupper()): print("Given string is in uppercase") else: print("Given string is not in uppercase")
Output:
Given string is not in uppercase
3)Checking if given number string is an uppercase or not
Assume we have a string that only contains numbers. Let’s use isupper to see if this string is uppercase or not ().
Below is the implementation:
# given string string = "28112001" # determining whether the given string is uppercase if(string.isupper()): print("Given string is in uppercase") else: print("Given string is not in uppercase")
Output:
Given string is not in uppercase
4)Checking if given string containing letters and numbers an uppercase or not
Assume we have a string that contains numbers and uppercase letters. Let’s use isupper to see if this string is uppercase or not ()
Below is the implementation:
# given string string = "BTECH-28112001" # determining whether the given string is uppercase if(string.isupper()): print("Given string is in uppercase") else: print("Given string is not in uppercase")
Output:
Given string is in uppercase
Explanation:
As string contains one or more upper case characters but no lower case characters. As a result, isupper() returned True.
5)Checking if given character is in uppercase or not
Individual characters have no data type in Python. A python string object can also be a single character. As a result, we can use the isupper() method to determine whether a character is upper case or not.
Below is the implementation:
# given string string = "S" # determining whether the given string is uppercase if(string.isupper()): print("Given char is in uppercase") else: print("Given char is not in uppercase")
Output:
Given char is in uppercase
Related Programs:
- python string upper method
- python string isupper method
- python program to create a class in which one method accepts a string from the user and another prints it
- convert integer to string in python
- how to convert a python string to int
- python how to get first n characters in a string
- python convert list to string