*Memo for a string and byte string(bytes
and bytearray
) functions:
- My post explains upper(), lower() and casefold().
- My post explains swapcase(), title() and capitalize().
*Memo for a string and byte string(bytes
and bytearray
):
str.isupper() and bytes.isupper() or bytearray.isupper() can check if the string and byte string 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
<Byte String(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
str.islower() and bytes.islower() or bytearray.islower() can check if the string and byte string 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
<Byte String(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
str.istitle() and bytes.istitle() or bytearray.istitle() can check if the string and byte string 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
<Byte String(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
Top comments (0)