字节的表示方法
单引号 b’still allows embedded “double” quotes’
双引号: b”still allows embedded ‘single’ quotes”.
三引号: b”’3 single quotes”’, b”“”3 double quotes”“”
字节相关方法
字节一般用16进制表示
方法 | 参数 | 描述 |
---|---|---|
bytes.fromhex(string) | 含有16进制的字符串,bytes.fromhex(‘2Ef0 F1f2 ‘) | 返回对应的字节 |
bytes.hex() | 将字节直接转换为字符串 | |
bytes.decode(encoding=”utf-8”, errors=”strict”) | 将字节解码成字符串 | |
str.encoding() | 表示编码类型的字符串,“gbk”,“utf8” | 将字符串编码为字节 |