Python String isupper() method
Python String isupper() method
The String.isupper() method in Python returns a boolean value ‘true’ if all cased characters in the string are uppercase else for any other value is returns false.
Syntax
String.isupper()
Parameter
NA
Return
This method returns a Boolean value true if all the characters in the specified string are uppercased else it returns false.
Example 1
# Python program explaining # the string.isupper() method # initializing the string value string = 'TUTORIALSANDEXAMPLES' print("String 1:",string) print("The above string is upper cased:",string.isupper()) #initializing second string value string = 'TutorialsAndEXAMPLES' print("String 2:",string) print("The above string is upper cased:",string.isupper())
Output
String 1: TUTORIALSANDEXAMPLES The above string is upper cased: True String 2: TutorialsAndEXAMPLES The above string is upper cased: False
Example 2
# Python program explaining # the string.isupper() method # initializing the string value string = "PYTHON IS AN EASY PROGRAMMING LANGUAGE" print("String 1:",string) if string.isupper() == True: print('The above string does not contain a lowercase letter.\n') else: print('The above string contains a uppercase letter.\n') string = "It IS VERY SIMPLE TO EXCEcute" print("String 2:",string) if string.isupper() == True: print('The above string does not contain a lowercase letter.') else: print('The above string contains a lowercase letter.')
Output
String 1: PYTHON IS AN EASY PROGRAMMING LANGUAGE The above string does not contain a lowercase letter. String 2: It IS VERY SIMPLE TO EXCEcute The above string contains lowercase letter.
Example 3
# Python program explaining # the string.isupper() method # initializing the string value string = "PYTHON IS AN EASY PROGRAMMING LANGUAGE" print(string.isupper()) # passing special characters string = "!@#HELLOWORLD" #return true the letters in the string are in uppercase print(string.isupper()) # passing whitespace string = "HELLO WORLD" #return true the letters in the string are in uppercase print(string.isupper()) # passing integer values in the string string = "HELLO123 WORLD123" #return true the letters in the string are in uppercase print(string.isupper()) string = "HellO123 WORLD123" #return false the some letters in the string are in lowercase print(string.isupper())
Output
True True True True False