Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why sum() doesn't work on array of bytes elements in python?

This code works perfectly:

b'\x4a' + b'\x20'
b'J '

But this doesn’t:

sum([b'\x4a', b'\x20'])
TypeError: unsupported operand type(s) for +: 'int' and 'bytes'

Why? How to concatenate many bytes elements?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use join instead:

b''.join([b'\x4a', b'\x20'])

Output:

b'J '
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading