Home >>Python Built-in Functions >Python bytes() Function
Python bytes() functionis used to return a bytes object. It converts given input objects into bytes objects or create empty bytes object of the given size. The difference between bytes() and bytearray() is that bytes() objects cannot be modified and bytearray() objects can be modified.
Syntax:bytes(x, encoding, error)
Parameter | Description |
---|---|
x | This parameter defines a source to use when creating the bytes object. |
encoding | This parameter defines the encoding of the string. |
error | This parameter defines what to do if the encoding fails. |
x = bytes(3) print(x)
x = bytes('Jërrÿ', 'ascii', errors = 'ignore') print(x)