Easy Tutorial
❮ Python List Swap Two Elements Python Att List Sort ❯

Python3 bytes Function

Python3 Built-in Functions


Description

The bytes function returns a new bytes object, which is an immutable sequence of integers in the range 0 <= x < 256. It is the immutable version of bytearray.

Syntax

Here is the syntax for bytes:

class bytes([source[, encoding[, errors]]])

Parameters

Return Value

Returns a new bytes object.


Examples

The following examples demonstrate the use of bytes:

>>> a = bytes([1,2,3,4])
>>> a
b'\x01\x02\x03\x04'
>>> type(a)
&lt;class 'bytes'>
>>>
>>> a = bytes('hello', 'ascii')
>>> a
b'hello'
>>> type(a)
&lt;class 'bytes'>
>>>

Python3 Built-in Functions

❮ Python List Swap Two Elements Python Att List Sort ❯