Python Length of Bytes

To find the length of a bytes object in Python, call len() builtin function and pass the bytes object as argument. len() function returns the number of bytes in the object.

Reference – Python len() builtin function

In the following example, we will take bytes object and find its length using len() function.

Python Program

bytesObject = b'\x65\x66\x67\x00\x10\x00\x00\x00\x04\x00'
length = len(bytesObject)
print(f'Length of this bytes object is {length}.')

Output

Length of this bytes object is 10.

Conclusion

In this Python Tutorial, we learned how to find the length of bytes object using len() function, with example program.