编码、for
3.5 for循环的时候,循环的每一个元素是”字符“
字符--------》字节
utf-8 ----->3字节
gbk --------->2字节
name = "小明"
for i in name:
bytes_list = bytes(i, encoding = "utf - 8") #默认的每一个字节都是16进制
for b in bytes_list: #转换十进制
c = bin(b) #转换二进制
print(c)
字节转换字符,字符转换字节
name = "小明"bytes_list = bytes(name, encoding = "utf - 8")print(bytes_list) new_name = str(bytes_list, encoding="utf-8")print(new_name)
时间: 2024-12-28 20:14:47