DEV Community

Super Kai (Kazuya Ito)
Super Kai (Kazuya Ito)

Posted on • Edited on

isupper, islower & istitle in Python

Buy Me a Coffee

*Memo for string, bytes and bytearray functions:

*Memo for a string, bytes and bytearray:

str.isupper() and bytes.isupper() or bytearray.isupper() can check if the string and bytes or bytearray respectively are uppercase and aren't empty as shown below:

*Memo:

  • Each has no arguments.

<String>:

print('PYTHON 3'.isupper()) # True  print('PYthON 3'.isupper()) print(''.isupper()) # False 
Enter fullscreen mode Exit fullscreen mode

<Bytes & Bytearray>:

print(b'PYTHON 3'.isupper()) print(bytearray(b'PYTHON 3').isupper()) # True  print(b'PYthON 3'.isupper()) print(bytearray(b'PYthON 3').isupper()) print(b''.isupper()) print(bytearray(b'').isupper()) # False 
Enter fullscreen mode Exit fullscreen mode

str.islower() and bytes.islower() or bytearray.islower() can check if the string and bytes or bytearray respectively are lowercase and aren't empty as shown below. *Each has no arguments:

<String>:

print('python 3'.islower()) # True  print('pyTHon 3'.islower()) print(''.islower()) # False 
Enter fullscreen mode Exit fullscreen mode

<Bytes & Bytearray>:

print(b'python 3'.islower()) print(bytearray(b'python 3').islower()) # True  print(b'pyTHon 3'.islower()) print(bytearray(b'pyTHon 3').islower()) print(b''.islower()) print(bytearray(b'').islower()) # False 
Enter fullscreen mode Exit fullscreen mode

str.istitle() and bytes.istitle() or bytearray.istitle() can check if the string and bytes or bytearray respectively are titlecased and aren't empty as shown below:

*Memo:

  • Each has no arguments.

<String>:

print('Python3'.istitle()) print('Python 3'.istitle()) print('John Smith'.istitle()) print('Johnsmith'.istitle()) # True  print('JohnSmith'.istitle()) print('John smith'.istitle()) print('john Smith'.istitle()) print('JohN SmitH'.istitle()) print(''.istitle()) # False 
Enter fullscreen mode Exit fullscreen mode

<Bytes & Bytearray>:

print(b'Python3'.istitle()) print(bytearray(b'Python3').istitle()) print(b'Python 3'.istitle()) print(bytearray(b'Python 3').istitle()) print(b'John Smith'.istitle()) print(bytearray(b'John Smith').istitle()) print(b'Johnsmith'.istitle()) print(bytearray(b'Johnsmith').istitle()) # True  print(b'JohnSmith'.istitle()) print(bytearray(b'JohnSmith').istitle()) print(b'John smith'.istitle()) print(bytearray(b'John smith').istitle()) print(b'john Smith'.istitle()) print(bytearray(b'john Smith').istitle()) print(b'JohN SmitH'.istitle()) print(bytearray(b'JohN SmitH').istitle()) print(b''.istitle()) print(bytearray(b'').istitle()) # False 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)