Python String isupper()


Python String isupper() method

Python String isupper() method is used to check if all cased characters in the string are upper case.

Consider that given string is in x.

x = "HELLO WORLD"

Then the return value of x.isupper() is

True

In this tutorial, you will learn the syntax and usage of String isupper() method in Python language.

Syntax of isupper() method

The syntax of String isupper() method in Python is given below.

str.isupper()

Parameters

The isupper() method takes no parameters.

Return value

isupper() method returns a boolean value of True if all cased characters in the string are upper case characters, and also there is at least one cased character in the string, otherwise False.

Examples

1. Check if given string is upper case in Python

In this example, we take a string value in variable my_string. We have to check if all cased characters in the string are upper case.

Call isupper() method on the string my_string and use the returned value as a condition in Python if else statement as shown in the following program.

Since all cased characters in the string are upper case, isupper() method returns True, and the if-block executes.

Python Program

my_string = "HELLO WORLD"

if my_string.isupper():
    print('Given string is UPPER CASE.')
else:
    print('Given string is NOT UPPER CASE.')

Output

Given string is UPPER CASE.

2. Check if given string (with all lower cased characters) is upper case in Python

In the following program, we take a string value in variable my_string such some of the characters in the string are lower case.

Since, not all cased characters in the string are upper case, isupper() method returns False, and the else-block executes.

Python Program

my_string = "Hello World"

if my_string.isupper():
    print('Given string is UPPER CASE.')
else:
    print('Given string is NOT UPPER CASE.')

Output

Given string is NOT UPPER CASE.

3. Check if given string (with no cased characters) is upper case in Python

In the following program, we take a string value in variable my_string such that there is no cased character in the string.

Since, there is no at least one cased character in the string, isupper() method returns False, and the else-block executes.

Python Program

my_string = ".@ -"

if my_string.isupper():
    print('Given string is UPPER CASE.')
else:
    print('Given string is NOT UPPER CASE.')

Output

Given string is NOT UPPER CASE.

Summary

In this tutorial of Python String Methods, we learned about String isupper() method, its syntax, and examples.