Skip to main content

bytes

def bytes(x, /)

bytes: construct a bytes value.

bytes(x) converts its argument to a bytes value.

If x is already a bytes value, the result is x.

If x is a string, its UTF-8 encoding is returned.

If x is an iterable of integers (each in 0–255), the bytes are constructed from those integer values.

bytes(b"hello") == b"hello"
bytes("hello") == b"hello"
bytes([104, 101, 108, 108, 111]) == b"hello"

bytes.elems

def bytes.elems(
) -> typing.Iterable[bytes]

Returns an iterable over the individual bytes as 1-byte bytes objects.

list(b"abc".elems()) == [b"a", b"b", b"c"]