Changing string to byte type in Python 2.7

前端 未结 5 1391
谎友^
谎友^ 2020-12-11 01:42

In python 3.2, i can change the type of an object easily. For example :

x=0
print(type (x))
x=bytes(0)
print(type (x))

it will give me this

5条回答
  •  -上瘾入骨i
    2020-12-11 02:26

    What can i do to change the type into a bytes type?

    You can't, there is no such type as 'bytes' in Python 2.7.

    From the Python 2.7 documentation (5.6 Sequence Types): "There are seven sequence types: strings, Unicode strings, lists, tuples, bytearrays, buffers, and xrange objects."

    From the Python 3.2 documentation (5.6 Sequence Types): "There are six sequence types: strings, byte sequences (bytes objects), byte arrays (bytearray objects), lists, tuples, and range objects."

提交回复
热议问题