醉东枫

关注

Python str与bytes之间的转换

醉东枫

关注

阅读 88

2022-02-10


# bytes object  
b = b"example"

# str object
s = "example"

# str to bytes
sb = bytes(s, encoding = "utf8")

# bytes to str
bs = str(b, encoding = "utf8")

# an alternative method
# str to bytes
sb2 = str.encode(s)

# bytes to str
bs2 = bytes.decode(b)



相关推荐

崭新的韭菜

python之bytes与str互转

崭新的韭菜 19 0 0

一ke大白菜

Python字符串与Bytes之间的互相转换

一ke大白菜 119 0 0

兽怪海北

Python系列(五):bytes和str的区别与联系

兽怪海北 65 0 0

覃榜言

Python学习之——str/unicode/bytes

覃榜言 41 0 0

半夜放水

Python错误TypeError: write() argument must be str, not bytes

半夜放水 86 0 0

拾光的Shelly

python中string、json、bytes的转换

拾光的Shelly 66 0 0

新鲜小饼干

在Python3中的bytes和str类型讲解

新鲜小饼干 47 0 0

女侠展昭

Python报错:TypeError: the JSON object must be str, bytes or bytearray, not ‘dict‘

女侠展昭 183 0 0

小铺有酒一两不够

python连接hive报错:TypeError: can‘t concat str to bytes

小铺有酒一两不够 37 0 0

何以至千里

Python学习:scapy库的Packet与str相互转换

何以至千里 66 0 0

精彩评论(0)

0 0 举报