bytes()
Built-in FunctionPython 2.0+Intermediate
Creates an immutable sequence of bytes
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
Learn by Difficulty
Quick Example
python
b = bytes([72, 101, 108, 108, 111]) print(b) print(bytes("hello", "utf-8"))
bytes() is a built-in function that creates an immutable sequence of bytes.
Try in PlaygroundTags
builtinfunctioncoredatatypebinaryimmutable
Related Items
bytearray()
Built-in Function
Creates a mutable sequence of bytes
memoryview()
Built-in Function
Creates a memory view object for binary data without copying
struct
Stdlib — Data
Pack and unpack binary data (C-style structs) to/from bytes
base64
Stdlib — Serialization
Encode/decode binary data as base64/base32/base16 text