DEV Community

natamacm
natamacm

Posted on

string isupper() and islower() methods with examples

Python string isupper() and islower() methods with Examples.

Python isupper() and islower() are in-built methods in Python, that are used to check if a string is in uppercase or lowercase. Internally it uses an if statement that checks the characters.

String isupper() method

isupper() returns "true" if all characters of the string are uppercase characters.

Syntax:

 String.isupper()
Enter fullscreen mode Exit fullscreen mode

Parameter:
None

Return type:

  • true - if all characters of the string are uppercase characters.
  • false - if any of the characters is not in uppercase character.

This works both in the Python shell and from a script

Python Example:

The example below shows how to use the isupper() method. The method is applied to the string directly.

string

So the methods isupper() and islower() both work with strings.

# s1 with all uppercase characters
s1 = "DEVTO"
print(s1.isupper())

# s2 with uppercase character, DOT, SPACE 
s2 = "DEV.TO"
print(s2.isupper())

# s3 with uppercase and lowercase characters
s3 ="DEV.to"
print(s3.isupper())

# s4 with all lowercase characters
s4 = "dev.to"
print(s4.isupper())
Enter fullscreen mode Exit fullscreen mode

The program above outputs this:

    True
    True
    False
    False
Enter fullscreen mode Exit fullscreen mode

2) String islower() method

The method islower() returns "true" if all characters of the string are lowercase characters.

Syntax:

 String.islower()
Enter fullscreen mode Exit fullscreen mode

Parameter:
None

Return type:

  • true - if all characters of the string are lowercase characters.
  • false - if any of the characters is not in lowercase character.

Python Example:

# s1 with all uppercase characters
s1 = "DEVTO"
print(s1.islower())

# s2 with uppercase character, DOT, SPACE 
s2 = "DEV.TO"
print(s2.islower())

# s3 with uppercase and lowercase characters
s3 ="DEV.to"
print(s3.islower())

# s4 with all lowercase characters
s4 = "dev.to"
print(s4.islower())
Enter fullscreen mode Exit fullscreen mode

The program above outputs this:

False
False
False
True
Enter fullscreen mode Exit fullscreen mode

Read more:

Top comments (0)