*Memo for string, bytes and bytearray functions:
- My post explains swapcase(), title() and capitalize().
- My post explains isupper(), islower() and istitle().
- My post explains encode() and decode().
*Memo for a string, bytes and bytearray:
str.upper() and bytes.upper() or bytearray.upper() can make the string and bytes or bytearray uppercase respectively for very caseless matching as shown below:
*Memo:
- Each has no arguments.
- The German Alphabet
ẞ
(ß
) is used after a long vowel or dipthong, like inStraße
orbeißen
. - The German Alphabets
SS
(ss
) are used after a short vowel sound, like inFluss
orKuss
.
<String>:
v = 'hElLo WoRlD'
print(v.upper())
# HELLO WORLD
v = 'ß' # Lowercase German Alphabet
print(v.upper())
# SS
v = 'ẞ' # Uppercase German Alphabet
print(v.upper())
# ẞ # Uppercase German Alphabet
<Bytes & Bytearray>:
v1 = b'hElLo WoRlD'
v2 = bytearray(b'hElLo WoRlD')
print(v1.upper())
# b'HELLO WORLD'
print(v2.upper())
# bytearray(b'HELLO WORLD')
# Lowercase German Alphabet
v1 = 'ß'.encode()
v1 = b'\xc3\x9f'
v2 = bytearray(b'\xc3\x9f')
print(v1.upper())
# b'\xc3\x9f'
print(v2.upper())
# bytearray(b'\xc3\x9f')
# Uppercase German Alphabet
v1 = 'ẞ'.encode()
v1 = b'\xe1\xba\x9e'
v2 = bytearray(b'\xe1\xba\x9e')
print(v1.upper())
# b'\xe1\xba\x9e'
print(v2.upper())
# bytearray(b'\xe1\xba\x9e')
str.lower() and bytes.lower() or bytearray.lower() can make the string and bytes or bytearray lowercase respectively for normal caseless matching as shown below:
*Memo:
- Each has no arguments.
<String>:
v = 'hElLo WoRlD'
print(v.lower())
# hello world
v = 'ß' # Lowercase German Alphabet
print(v.lower())
# ß # Lowercase German Alphabet
v = 'ẞ' # Uppercase German Alphabet
print(v.lower())
# ß # Lowercase German Alphabet
<Bytes & Bytearray>:
v1 = b'hElLo WoRlD'
v2 = bytearray(b'hElLo WoRlD')
print(v1.lower())
# b'hello world'
print(v2.lower())
# bytearray(b'hello world')
# Lowercase German Alphabet
v1 = 'ß'.encode()
v1 = b'\xc3\x9f'
v2 = bytearray(b'\xc3\x9f')
print(v1.lower())
# b'\xc3\x9f'
print(v2.lower())
# bytearray(b'\xc3\x9f')
# Uppercase German Alphabet
v1 = 'ẞ'.encode()
v1 = b'\xe1\xba\x9e'
v2 = bytearray(b'\xe1\xba\x9e')
print(v1.lower())
# b'\xe1\xba\x9e'
print(v2.lower())
# bytearray(b'\xe1\xba\x9e')
str.casefold() can make the string lowercase for very caseless matching as shown below:
*Memo:
- It has no arguments.
-
bytes.casefold()
andbytearray.lower()
don't exist for a bytes and bytearray respectively.
<String>:
v = 'hElLo WoRlD'
print(v.casefold())
# hello world
v = 'ß' # Lowercase German Alphabet
print(v.casefold())
# ss
v = 'ẞ' # Uppercase German Alphabet
print(v.casefold())
# ss
Top comments (0)