Python 3.x and bytes

E

Ethan Furman

In Python 3 one can say

--> huh = bytes(5)

Since the bytes type is actually a list of integers, I would have
expected this to have huh being a bytestring with one element -- the
integer 5. Actually, what you get is:

--> huh
b'\x00\x00\x00\x00\x00'

or five null bytes. Note that this is an immutable type, so you cannot
go in later and say

--> huh[3] = 9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'bytes' object does not support item assignment


So, out of curiosity, does anyone actually use this, um, feature?

~Ethan~
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top