On this page
  1. bytes
  2. Import & Availability
  3. Overview & Signature
  4. Common Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

bytes

Prev: bytearray | Up: __builtins__ | Next: callable
Rel: bool, int, float, complex, str
Ref: docs.python.org — bytes
Tags: #public #python3 #builtins


Import & Availability

# Built-in (available globally without import)
from builtins import bytes

Overview & Signature

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

Common Methods & Attributes

Usage

raw = bytes([65, 66, 67])
assert raw == b"ABC" and raw[0] == 65 and raw.decode("ascii") == "ABC"
assert bytes.fromhex("48 69") == b"Hi"

Gotchas

REPL Inspect

help(bytes)

Linked from

Related notes