On this page
builtins.bytearray
Prev: builtins.BufferError | Up: builtins | Next: builtins.bytes
Rel: builtins.abs, builtins.aiter, builtins.all, builtins.anext
Ref: docs.python.org — builtins.bytearray
Tags: #public #python3 #stdlib #builtins
Import
import builtins
from builtins import bytearray
Signature & Overview
builtins.bytearray(iterable_of_ints) -> bytearray
bytearray(string, encoding[, errors]) -> bytearray bytearray(bytes_or_buffer) -> mutable copy of bytes_or_buffer bytearray(int) -> bytes array of size given by the parameter initialized with null bytes
Methods & Attributes
bytearray.append(self, item, /)— Append a single item to the end of the bytearray.bytearray.capitalize(self, /)— Return a copy of B with only its first character capitalized (ASCII) and the rest lower-cased.bytearray.center(self, width, fillchar=b' ', /)— Return a centered string of length width.bytearray.clear(self, /)— Remove all items from the bytearray.bytearray.copy(self, /)— Return a copy of B.bytearray.count(...)— Return the number of non-overlapping occurrences of subsection 'sub' in bytes B[start:end].bytearray.decode(self, /, encoding='utf-8', errors='strict')— Decode the bytearray using the codec registered for encoding.bytearray.endswith(...)— Return True if the bytearray ends with the specified suffix, False otherwise.bytearray.expandtabs(self, /, tabsize=8)— Return a copy where all tab characters are expanded using spaces.bytearray.extend(self, iterable_of_ints, /)— Append all the items from the iterator or sequence to the end of the bytearray.bytearray.find(...)— Return the lowest index in B where subsection 'sub' is found, such that 'sub' is contained within B[start:end].bytearray.fromhex(string, /)— Create a bytearray object from a string of hexadecimal numbers.bytearray.hex(...)— Create a string of hexadecimal numbers from a bytearray object.bytearray.index(...)— Return the lowest index in B where subsection 'sub' is found, such that 'sub' is contained within B[start:end].bytearray.insert(self, index, item, /)— Insert a single item into the bytearray before the given index.bytearray.isalnum(self, /)— Return True if all characters in B are alphanumeric and there is at least one character in B, False otherwise.bytearray.isalpha(self, /)— Return True if all characters in B are alphabetic and there is at least one character in B, False otherwise.bytearray.isascii(self, /)— Return True if B is empty or all characters in B are ASCII, False otherwise.bytearray.isdigit(self, /)— Return True if all characters in B are digits and there is at least one character in B, False otherwise.bytearray.islower(self, /)— Return True if all cased characters in B are lowercase and there is at least one cased character in B, False otherwise.bytearray.isspace(self, /)— Return True if all characters in B are whitespace and there is at least one character in B, False otherwise.bytearray.istitle(self, /)— Return True if B is a titlecased string and there is at least one character in B, i.e. uppercase characters may only follow uncased characters and lowercase characters only cased ones. Return Falsebytearray.isupper(self, /)— Return True if all cased characters in B are uppercase and there is at least one cased character in B, False otherwise.bytearray.join(self, iterable_of_bytes, /)— Concatenate any number of bytes/bytearray objects.bytearray.ljust(self, width, fillchar=b' ', /)— Return a left-justified string of length width.bytearray.lower(self, /)— Return a copy of B with all ASCII characters converted to lowercase.bytearray.lstrip(self, bytes=None, /)— Strip leading bytes contained in the argument.bytearray.maketrans(frm, to, /)— Return a translation table usable for the bytes or bytearray translate method.bytearray.partition(self, sep, /)— Partition the bytearray into three parts using the given separator.bytearray.pop(self, index=-1, /)— Remove and return a single item from B.bytearray.remove(self, value, /)— Remove the first occurrence of a value in the bytearray.bytearray.removeprefix(self, prefix, /)— Return a bytearray with the given prefix string removed if present.bytearray.removesuffix(self, suffix, /)— Return a bytearray with the given suffix string removed if present.bytearray.replace(self, old, new, count=-1, /)— Return a copy with all occurrences of substring old replaced by new.bytearray.resize(self, size, /)— Resize the internal buffer of bytearray to len.bytearray.reverse(self, /)— Reverse the order of the values in B in place.bytearray.rfind(...)— Return the highest index in B where subsection 'sub' is found, such that 'sub' is contained within B[start:end].bytearray.rindex(...)— Return the highest index in B where subsection 'sub' is found, such that 'sub' is contained within B[start:end].bytearray.rjust(self, width, fillchar=b' ', /)— Return a right-justified string of length width.bytearray.rpartition(self, sep, /)— Partition the bytearray into three parts using the given separator.
Usage
buf = bytearray(b"hello")
buf[0] = ord("H")
buf.extend(b"!")
assert bytes(buf) == b"Hello!"
Gotchas
- Mutable counterpart to
bytes: Unhashable (cannot be adictkey); indexingbuf[0]returns anint(0..255), not a 1-bytebytes.
REPL Inspect
from builtins import bytearray
help(bytearray)
Linked from
Related notes
- tuts/python3/stdlib_module/builtins/BufferError Linked here; links to this page; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/bytes Linked here; links to this page; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/builtins/abs Linked here; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/aiter Linked here; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/all Linked here; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/anext Linked here; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/any shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/ArithmeticError shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/ascii shared tags: #builtins, #stdlib