Startswith (Startswith (: Bytes-Like Object
Startswith (Startswith (: Bytes-Like Object
Startswith (Startswith (: Bytes-Like Object
4 documentation
Set the table argument to None for translations that only delete characters:
The following methods on bytes and bytearray objects have default behaviours that assume the use
of ASCII compatible binary formats, but can still be used with arbitrary binary data by passing
appropriate arguments. Note that all of the bytearray methods in this section do not operate in place,
and instead produce new objects.
Note: The bytearray version of this method does not operate in place - it always produces a
new object, even if no changes were made.
https://docs.python.org/3/library/stdtypes.html#old-string-formatting 40/74
7/14/2020 Built-in Types — Python 3.8.4 documentation
Note: The bytearray version of this method does not operate in place - it always produces a
new object, even if no changes were made.
bytes. lstrip([chars])
bytearray. lstrip([chars])
Return a copy of the sequence with specified leading bytes removed. The chars argument is a
binary sequence specifying the set of byte values to be removed - the name refers to the fact
this method is usually used with ASCII characters. If omitted or None , the chars argument
defaults to removing ASCII whitespace. The chars argument is not a prefix; rather, all
combinations of its values are stripped:
The binary sequence of byte values to remove may be any bytes-like object.
Note: The bytearray version of this method does not operate in place - it always produces a
new object, even if no changes were made.
Note: The bytearray version of this method does not operate in place - it always produces a
new object, even if no changes were made.
bytes. rstrip([chars])
bytearray. rstrip([chars])
Return a copy of the sequence with specified trailing bytes removed. The chars argument is a
binary sequence specifying the set of byte values to be removed - the name refers to the fact
this method is usually used with ASCII characters. If omitted or None , the chars argument
https://docs.python.org/3/library/stdtypes.html#old-string-formatting 41/74
7/14/2020 Built-in Types — Python 3.8.4 documentation
defaults to removing ASCII whitespace. The chars argument is not a suffix; rather, all
combinations of its values are stripped:
The binary sequence of byte values to remove may be any bytes-like object.
Note: The bytearray version of this method does not operate in place - it always produces a
new object, even if no changes were made.
If sep is given, consecutive delimiters are not grouped together and are deemed to delimit
empty subsequences (for example, b'1,,2'.split(b',') returns [b'1', b'', b'2'] ). The
sep argument may consist of a multibyte sequence (for example, b'1<>2<>3'.split(b'<>')
returns [b'1', b'2', b'3'] ). Splitting an empty sequence with a specified separator returns
[b''] or [bytearray(b'')] depending on the type of object being split. The sep argument may
be any bytes-like object.
For example:
If sep is not specified or is None , a different splitting algorithm is applied: runs of consecutive
ASCII whitespace are regarded as a single separator, and the result will contain no empty
strings at the start or end if the sequence has leading or trailing whitespace. Consequently,
splitting an empty sequence or a sequence consisting solely of ASCII whitespace without a
specified separator returns [] .
For example:
https://docs.python.org/3/library/stdtypes.html#old-string-formatting 42/74
7/14/2020 Built-in Types — Python 3.8.4 documentation
bytes. strip([chars])
bytearray. strip([chars])
Return a copy of the sequence with specified leading and trailing bytes removed. The chars
argument is a binary sequence specifying the set of byte values to be removed - the name
refers to the fact this method is usually used with ASCII characters. If omitted or None , the chars
argument defaults to removing ASCII whitespace. The chars argument is not a prefix or suffix;
rather, all combinations of its values are stripped:
The binary sequence of byte values to remove may be any bytes-like object.
Note: The bytearray version of this method does not operate in place - it always produces a
new object, even if no changes were made.
The following methods on bytes and bytearray objects assume the use of ASCII compatible binary
formats and should not be applied to arbitrary binary data. Note that all of the bytearray methods in
this section do not operate in place, and instead produce new objects.
bytes. capitalize()
bytearray. capitalize()
Return a copy of the sequence with each byte interpreted as an ASCII character, and the first
byte capitalized and the rest lowercased. Non-ASCII byte values are passed through
unchanged.
Note: The bytearray version of this method does not operate in place - it always produces a
new object, even if no changes were made.
bytes. expandtabs(tabsize=8)
bytearray. expandtabs(tabsize=8)
Return a copy of the sequence where all ASCII tab characters are replaced by one or more
ASCII spaces, depending on the current column and the given tab size. Tab positions occur
every tabsize bytes (default is 8, giving tab positions at columns 0, 8, 16 and so on). To expand
the sequence, the current column is set to zero and the sequence is examined byte by byte. If
the byte is an ASCII tab character ( b'\t' ), one or more space characters are inserted in the
result until the current column is equal to the next tab position. (The tab character itself is not
https://docs.python.org/3/library/stdtypes.html#old-string-formatting 43/74
7/14/2020 Built-in Types — Python 3.8.4 documentation
copied.) If the current byte is an ASCII newline ( b'\n' ) or carriage return ( b'\r' ), it is copied
and the current column is reset to zero. Any other byte value is copied unchanged and the
current column is incremented by one regardless of how the byte value is represented when
printed:
Note: The bytearray version of this method does not operate in place - it always produces a
new object, even if no changes were made.
bytes. isalnum()
bytearray. isalnum()
Return True if all bytes in the sequence are alphabetical ASCII characters or ASCII decimal
digits and the sequence is not empty, False otherwise. Alphabetic ASCII characters are those
byte values in the sequence b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' .
ASCII decimal digits are those byte values in the sequence b'0123456789' .
For example:
bytes. isalpha()
bytearray. isalpha()
Return True if all bytes in the sequence are alphabetic ASCII characters and the sequence is
not empty, False otherwise. Alphabetic ASCII characters are those byte values in the sequence
b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' .
For example:
bytes. isascii()
bytearray. isascii()
Return True if the sequence is empty or all bytes in the sequence are ASCII, False otherwise.
ASCII bytes are in the range 0-0x7F.
https://docs.python.org/3/library/stdtypes.html#old-string-formatting 44/74
7/14/2020 Built-in Types — Python 3.8.4 documentation
bytes. isdigit()
bytearray. isdigit()
Return True if all bytes in the sequence are ASCII decimal digits and the sequence is not empty,
False otherwise. ASCII decimal digits are those byte values in the sequence b'0123456789' .
For example:
bytes. islower()
bytearray. islower()
Return True if there is at least one lowercase ASCII character in the sequence and no
uppercase ASCII characters, False otherwise.
For example:
bytes. isspace()
bytearray. isspace()
Return True if all bytes in the sequence are ASCII whitespace and the sequence is not empty,
False otherwise. ASCII whitespace characters are those byte values in the sequence b'
\t\n\r\x0b\f' (space, tab, newline, carriage return, vertical tab, form feed).
bytes. istitle()
bytearray. istitle()
Return True if the sequence is ASCII titlecase and the sequence is not empty, False otherwise.
See bytes.title() for more details on the definition of “titlecase”.
For example:
https://docs.python.org/3/library/stdtypes.html#old-string-formatting 45/74