This article will discuss how to use the isupper() method of String class in Python.
Table of Contents
In Python, the string class (Str) provides a member function isupper() to check if a string is an uppercase string or not.
Syntax of isupper() method
Str.isupper()
Parameters:
- It does not accept any parameter.
Returns:
- It returns True if the calling string object contains all the uppercase characters. Whereas, it returns False if any of the characters in the string is of lowercase.
- It also returns False, if the string does not contain an upper case character.
Examples of issupper() method of string in Python
Check if a string is an uppercase string or not
We can check if a string is an uppercase string or not using isuuper() function. If all the the string characters are upper case characters, then isupper() returns True.
Example 1:
str_obj = 'SAMPLE STRING' if str_obj.isupper(): print('String is an uppercase string') else: print('String is not an uppercase string')
Output
String is an uppercase string
Example 2:
str_obj = 'Sample String' if str_obj.isupper(): print('String is an uppercase string') else: print('String is not an uppercase string')
Output:
String is not an uppercase string
As few characters in the string are lower case characters, therefore, isupper() returned False.
Check if a string containing numbers is uppercase or not
Suppose we have a string containing numbers only. Let’s check if this string is an uppercase string or not using isupper(),
str_obj = '123 345' if str_obj.isupper(): print('String is an uppercase string') else: print('String is not an uppercase string')
Output:
String is not an uppercase string
As string does not have any upper case character, so isupper() returned False.
Check if a string containing letters & numbers is uppercase or not
Suppose we have a string containing numbers and some upper case letters. Let’s check if this string is an uppercase string or not using isupper(),
str_obj = 'Simply 123' if str_obj.isupper(): print('String is an uppercase string') else: print('String is not an uppercase string')
Output:
String is not an uppercase string
As string does not have any lower case character, but has one or more upper case characters. So isupper() returned True.
Check if a character is uppercase or not
There is no data type for individual characters in Python. A single character is also a python string object. So, we can use isupper() method to check if a character is upper case character or not,
str_obj = 'S' if str_obj.isupper(): print('Character is an uppercase character') else: print('Character is not an uppercase character')
Output:
Character is an uppercase character
Summary
Using isupper() function, we can check if a string is uppercase string or not.
Pandas Tutorials -Learn Data Analysis with Python
-
Pandas Tutorial Part #1 - Introduction to Data Analysis with Python
-
Pandas Tutorial Part #2 - Basics of Pandas Series
-
Pandas Tutorial Part #3 - Get & Set Series values
-
Pandas Tutorial Part #4 - Attributes & methods of Pandas Series
-
Pandas Tutorial Part #5 - Add or Remove Pandas Series elements
-
Pandas Tutorial Part #6 - Introduction to DataFrame
-
Pandas Tutorial Part #7 - DataFrame.loc[] - Select Rows / Columns by Indexing
-
Pandas Tutorial Part #8 - DataFrame.iloc[] - Select Rows / Columns by Label Names
-
Pandas Tutorial Part #9 - Filter DataFrame Rows
-
Pandas Tutorial Part #10 - Add/Remove DataFrame Rows & Columns
-
Pandas Tutorial Part #11 - DataFrame attributes & methods
-
Pandas Tutorial Part #12 - Handling Missing Data or NaN values
-
Pandas Tutorial Part #13 - Iterate over Rows & Columns of DataFrame
-
Pandas Tutorial Part #14 - Sorting DataFrame by Rows or Columns
-
Pandas Tutorial Part #15 - Merging or Concatenating DataFrames
-
Pandas Tutorial Part #16 - DataFrame GroupBy explained with examples
Are you looking to make a career in Data Science with Python?
Data Science is the future, and the future is here now. Data Scientists are now the most sought-after professionals today. To become a good Data Scientist or to make a career switch in Data Science one must possess the right skill set. We have curated a list of Best Professional Certificate in Data Science with Python. These courses will teach you the programming tools for Data Science like Pandas, NumPy, Matplotlib, Seaborn and how to use these libraries to implement Machine learning models.
Checkout the Detailed Review of Best Professional Certificate in Data Science with Python.
Remember, Data Science requires a lot of patience, persistence, and practice. So, start learning today.