Check if the characters of a string are uppercase or lowercase values in Python

Hello friends, in this tutorial, I will tell how to check if the characters of a string are uppercase or lowercase values in Python.

Check if the characters of a string are uppercase or lowercase values

The tutorial covers how to check if the characters of a string are :

  • uppercase
  • lowercase

isupper() function is used to check if the characters are uppercase or not. It returns a boolean value, true if the character are uppercase and false otherwise. Here I have taken an example, where sample_Str stores a string value. I’ve then attributed it along with the isupper() function to check if the character are uppercase values or not.

Code :

sample_Str = 'CODESPEEDY'
result = sample_Str.isupper()
print(result)

As the chosen string value is in uppercase, I get an output as True.

Output :

True

islower() function is used to check if the characters are lowercase values or not. It also returns a boolean value. I’ve replaced isupper() function to islower() from the previous example. As the characters are uppercase values, it returns False as output.

Code :

sample_Str = 'CODESPEEDY'
result = sample_Str.islower()
print(result)

Output :

False

Thus you can now check if the characters of a string are uppercase or lowercase values in Python.

Leave a Reply

Your email address will not be published. Required fields are marked *