Python中数据类型的转换

bytes<-->str

a="hello"  #str字符型

#str转换为bytes类型
b=a.encode("utf-8")  或  b=bytes(a,encoding="utf-8")

#bytes类型转换为str类型
c=b.decode("utf-8")  或  c=str(b,encoding="utf-8")

猜你喜欢

转载自blog.csdn.net/qq_36119192/article/details/83687647