We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Python string isupper() method

This article will discuss how to use the isupper() method of String class in Python.

Table of Contents

Advertisements

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.

Cart

Your Cart is Empty

Back To Shop