PyDocs

Nav

Python Runtime Services

bytes

  • bytes(source=b'')
  • bytes(source, encoding, errors='strict')
bytes(iterable_of_ints) -> bytes
bytes(string, encoding[, errors]) -> bytes
bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer
bytes(int) -> bytes object of size given by the parameter initialized with null bytes
bytes() -> empty bytes object

Construct an immutable array of bytes from:
  - an iterable yielding integers in range(256)
  - a text string encoded using the specified encoding
  - any object implementing the buffer API.
  - an integer
Members of bytes

c

capitalize
Return a copy of B with only its first character capitalized (ASCII) and the rest lower-cased.
center
Return a centered string of length width.
count
Return the number of non-overlapping occurrences of subsection 'sub' in bytes B[start:end].

d

decode
Decode the bytes using the codec registered for encoding.

e

endswith
Return True if the bytes ends with the specified suffix, False otherwise.
expandtabs
Return a copy where all tab characters are expanded using spaces.

f

find
Return the lowest index in B where subsection 'sub' is found, such that 'sub' is contained within B[start,end].
fromhex
Create a bytes object from a string of hexadecimal numbers.

h

hex
Create a string of hexadecimal numbers from a bytes object.

i

index
Return the lowest index in B where subsection 'sub' is found, such that 'sub' is contained within B[start,end].
isalnum
Return True if all characters in B are alphanumeric and there is at least one character in B, False otherwise.
isalpha
Return True if all characters in B are alphabetic and there is at least one character in B, False otherwise.
isascii
Return True if B is empty or all characters in B are ASCII, False otherwise.
isdigit
Return True if all characters in B are digits and there is at least one character in B, False otherwise.
islower
Return True if all cased characters in B are lowercase and there is at least one cased character in B, False otherwise.
isspace
Return True if all characters in B are whitespace and there is at least one character in B, False otherwise.
istitle
Return True if B is a titlecased string and there is at least one character in B, i.e.
isupper
Return True if all cased characters in B are uppercase and there is at least one cased character in B, False otherwise.

j

join
Concatenate any number of bytes objects.

l

ljust
Return a left-justified string of length width.
lower
Return a copy of B with all ASCII characters converted to lowercase.
lstrip
Strip leading bytes contained in the argument.

m

maketrans
Return a translation table usable for the bytes or bytearray translate method.

p

partition
Partition the bytes into three parts using the given separator.

r

removeprefix
Return a bytes object with the given prefix string removed if present.
removesuffix
Return a bytes object with the given suffix string removed if present.
replace
Return a copy with all occurrences of substring old replaced by new.
rfind
Return the highest index in B where subsection 'sub' is found, such that 'sub' is contained within B[start,end].
rindex
Return the highest index in B where subsection 'sub' is found, such that 'sub' is contained within B[start,end].
rjust
Return a right-justified string of length width.
rpartition
Partition the bytes into three parts using the given separator.
rsplit
Return a list of the sections in the bytes, using sep as the delimiter.
rstrip
Strip trailing bytes contained in the argument.

s

split
Return a list of the sections in the bytes, using sep as the delimiter.
splitlines
Return a list of the lines in the bytes, breaking at line boundaries.
startswith
Return True if the bytes starts with the specified prefix, False otherwise.
strip
Strip leading and trailing bytes contained in the argument.
swapcase
Return a copy of B with uppercase ASCII characters converted to lowercase ASCII and vice versa.

t

title
Return a titlecased version of B, i.e.
translate
Return a copy with each character mapped by the given translation table.

u

upper
Return a copy of B with all ASCII characters converted to uppercase.

z

zfill
Pad a numeric string with zeros on the left, to fill a field of the given width.
0 Examples
No examples for builtins/bytes.
See Also
No see-alsos for builtins/bytes
0 Notes
No notes for bytes