1 # bytes object 2 b = b"example" 3 4 # str object 5 s = "example" 6 7 # str to bytes 8 bytes(s, encoding = "utf8") 9 10 # bytes to str 11 str(b, encoding = "utf-8") 12 13 # an alternative method 14 # str to bytes 15 str.encode(s) 16 17 # bytes to str 18 bytes.decode(b)
原文地址:https://www.cnblogs.com/ceshixuexi/p/8280711.html
时间: 2024-10-28 22:05:25