*Memo for string, bytes and bytearray functions:
*Memo for a string, bytes and bytearray:
str.lstrip() and bytes.lstrip() or bytearray.lstrip() can remove zero or more characters and bytes from the left side of the string and bytes or bytearray one by one respectively as shown below:
*Memo:
- The 1st argument is
chars
(Optional-Defualt:None
-Type:str
forstr.lstrip()
, Bytes-like object forbytes.lstrip()
andbytearray.lstrip()
or NoneType):- It's the zero or more characters and bytes to remove from the left side of the string and bytes or bytearray one by one respectively.
- Its each character and byte are considered one by one so it's not a prefix respectively.
- If it's not set or
None
," "
is set. - Don't use
chars=
.
<String>:
v = " aa bb cc "
# ↑↑ ↑↑
print('"' + v.lstrip() + '"')
print('"' + v.lstrip(" ") + '"')
print('"' + v.lstrip("c ") + '"')
print('"' + v.lstrip(" c") + '"')
print('"' + v.lstrip(" ABC ") + '"')
# "aa bb cc "
# ↑↑
print('"' + v.lstrip("a ") + '"')
print('"' + v.lstrip(" a") + '"')
print('"' + v.lstrip("ac ") + '"')
print('"' + v.lstrip(" ac") + '"')
print('"' + v.lstrip("a c") + '"')
# "bb cc "
# ↑↑
print('"' + v.lstrip("") + '"')
print('"' + v.lstrip("a") + '"')
print('"' + v.lstrip("c") + '"')
print('"' + v.lstrip("ac") + '"')
# " aa bb cc "
# ↑↑ ↑↑
<Bytes & Bytearray>:
bytes:
v = b" aa bb cc "
# ↑↑ ↑↑
print(v.lstrip())
print(v.lstrip(b" "))
print(v.lstrip(bytearray(b" ")))
print(v.lstrip(b"c "))
print(v.lstrip(bytearray(b"c ")))
print(v.lstrip(b" c"))
print(v.lstrip(bytearray(b" c")))
print(v.lstrip(b" ABC "))
print(v.lstrip(bytearray(b" ABC ")))
# b'aa bb cc '
# ↑↑
print(v.lstrip(b"a "))
print(v.lstrip(bytearray(b"a ")))
print(v.lstrip(b" a"))
print(v.lstrip(bytearray(b" a")))
print(v.lstrip(b"ac "))
print(v.lstrip(bytearray(b"ac ")))
print(v.lstrip(b" ac"))
print(v.lstrip(bytearray(b" ac")))
print(v.lstrip(b"a c"))
print(v.lstrip(bytearray(b"a c")))
# b'bb cc '
# ↑↑
print(v.lstrip(b""))
print(v.lstrip(bytearray(b"")))
print(v.lstrip(b"a"))
print(v.lstrip(bytearray(b"a")))
print(v.lstrip(b"c"))
print(v.lstrip(bytearray(b"c")))
print(v.lstrip(b"ac"))
print(v.lstrip(bytearray(b"ac")))
# b' aa bb cc '
# ↑↑ ↑↑
bytearray:
v = bytearray(b" aa bb cc ")
# ↑↑ ↑↑
print(v.lstrip())
print(v.lstrip(b" "))
print(v.lstrip(bytearray(b" ")))
print(v.lstrip(b"c "))
print(v.lstrip(bytearray(b"c ")))
print(v.lstrip(b" c"))
print(v.lstrip(bytearray(b" c")))
print(v.lstrip(b" ABC "))
print(v.lstrip(bytearray(b" ABC ")))
# bytearray(b'aa bb cc ')
# ↑↑
print(v.lstrip(b"a "))
print(v.lstrip(bytearray(b"a ")))
print(v.lstrip(b" a"))
print(v.lstrip(bytearray(b" a")))
print(v.lstrip(b"ac "))
print(v.lstrip(bytearray(b"ac ")))
print(v.lstrip(b" ac"))
print(v.lstrip(bytearray(b" ac")))
print(v.lstrip(b"a c"))
print(v.lstrip(bytearray(b"a c")))
# bytearray(b'bb cc ')
# ↑↑
print(v.lstrip(b""))
print(v.lstrip(bytearray(b"")))
print(v.lstrip(b"a"))
print(v.lstrip(bytearray(b"a")))
print(v.lstrip(b"c"))
print(v.lstrip(bytearray(b"c")))
print(v.lstrip(b"ac"))
print(v.lstrip(bytearray(b"ac")))
# bytearray(b' aa bb cc ')
# ↑↑ ↑↑
Top comments (0)