*Memo for string, bytes and bytearray functions:
- My post explains upper(), lower() and casefold().
- My post explains isupper(), islower() and istitle().
- My post explains encode() and decode().
*Memo for a string, bytes and bytearray:
str.swapcase() and bytes.swapcase() or bytearray.swapcase() can swap each character's case and byte's case of the string and bytes or bytearray respectively from uppercase to lowercase and from lowercase to uppercasee as shown below:
*Memo:
- Each has no arguments.
<String>:
v = 'hElLo WoRlD'
print(v.swapcase())
# HeLlO wOrLd
v = 'ß' # Lowercase German Alphabet
print(v.swapcase())
# SS
v = 'ẞ' # Uppercase German Alphabet
print(v.swapcase())
# ß # Lowercase German Alphabet
<Bytes & Bytearray>:
v1 = b'hElLo WoRlD'
v2 = bytearray(b'hElLo WoRlD')
print(v1.swapcase())
# b'HeLlO wOrLd'
print(v2.swapcase())
# bytearray(b'HeLlO wOrLd')
# Lowercase German Alphabet
v1 = 'ß'.encode()
v1 = b'\xc3\x9f'
v2 = bytearray(b'\xc3\x9f')
print(v1.swapcase())
# b'\xc3\x9f'
print(v2.swapcase())
# bytearray(b'\xc3\x9f')
# Uppercase German Alphabet
v1 = 'ẞ'.encode()
v1 = b'\xe1\xba\x9e'
v2 = bytearray(b'\xe1\xba\x9e')
print(v1.swapcase())
# b'\xe1\xba\x9e'
print(v2.swapcase())
# bytearray(b'\xe1\xba\x9e')
str.title() and bytes.title() or bytearray.title() can make the string and bytes or bytearray titlecased respectively as shown below:
*Memo:
- Each has no arguments.
<String>:
v = 'hElLo WoRlD'
print(v.title())
# Hello World
v = 'ß' # Lowercase German Alphabet
print(v.title())
# Ss
v = 'ẞ' # Uppercase German Alphabet
print(v.title())
# ẞ # Uppercase German Alphabet
<Bytes & Bytearray>:
v1 = b'hElLo WoRlD'
v2 = bytearray(b'hElLo WoRlD')
print(v1.title())
# b'Hello World'
print(v2.title())
# bytearray(b'Hello World')
# Lowercase German Alphabet
v1 = 'ß'.encode()
v1 = b'\xc3\x9f'
v2 = bytearray(b'\xc3\x9f')
print(v1.title())
# b'\xc3\x9f'
print(v2.title())
# bytearray(b'\xc3\x9f')
# Uppercase German Alphabet
v1 = 'ẞ'.encode()
v1 = b'\xe1\xba\x9e'
v2 = bytearray(b'\xe1\xba\x9e')
print(v1.title())
# b'\xe1\xba\x9e'
print(v2.title())
# bytearray(b'\xe1\xba\x9e')
str.capitalize() and bytes.capitalize() or bytearray.capitalize() can capitalize the string and bytes or bytearray respectively as shown below:
*Memo:
- Each has no arguments.
<String>:
v = 'hello world'
print(v.capitalize())
# Hello world
v = 'ß' # Lowercase German Alphabet
print(v.capitalize())
# Ss
v = 'ẞ' # Uppercase German Alphabet
print(v.capitalize())
# ẞ # Uppercase German Alphabet
<Bytes & Bytearray>:
v1 = b'hello world'
v2 = bytearray(b'hello world')
print(v1.capitalize())
# b'Hello world'
print(v2.capitalize())
# bytearray(b'Hello world')
# Lowercase German Alphabet
v1 = 'ß'.encode()
v1 = b'\xc3\x9f'
v2 = bytearray(b'\xc3\x9f')
print(v1.capitalize())
# b'\xc3\x9f'
print(v2.capitalize())
# bytearray(b'\xc3\x9f')
# Uppercase German Alphabet
v1 = 'ẞ'.encode()
v1 = b'\xe1\xba\x9e'
v2 = bytearray(b'\xe1\xba\x9e')
print(v1.capitalize())
# b'\xe1\xba\x9e'
print(v2.capitalize())
# bytearray(b'\xe1\xba\x9e')
Top comments (0)