Skip to content
Home » Python Programs » Python b

Python b

Python b denotes a bytes object is returned by the bytes() function. It can convert things to bytes objects or create empty bytes objects of any size. The distinction between bytes() and bytearray() is that bytes() returns a non-modifiable object, whereas bytearray() returns a modifiable object.

Bytes Datatypes in Python

Bytes is an immutable variant of bytearray with the same non-mutating methods, indexing, and slicing behaviour as bytearray. bytearray() is a function that returns a list of bytes. Return a new byte array. The bytearray type is a modifiable series of integers in the range 0 to x 256 that can be changed.

Prefix b in Python

Bytes are literals that represent integers between 0 and 255, commonly known as octets, whereas str is a literal that has a sequence of Unicode characters encoded in UTF-16 or UTF-32, and this is entirely dependent on Python compilation. By appending the prefix b to a regular string, we were able to transform its datatype from string to bytes.

type() in Python

Python includes a built-in method called type() that may be used to determine the class type of a variable. In Python, the type() method returns the data type of the object that is supplied as an argument.

Python b

my_text = 'Welcome to Inlarn'
my_text_sample = b'Welcome to Inlarn'


<class ‘str’>
<class ‘bytes’>