问题解决,总结下:
方法:
"""bytes([40]) == b'('
chr(40) == '('
chr(40).encode() == b'('
return '\\x{:02x}'.format(40)
"""
实验:
for i in range(256):
print(i, ": ", chr(i).encode()) #bytes
for i in range(256):
print(i, ": ", i.to_bytes(1, 'little')) #bytes
for i in range(256):
print(i, ": ", '\\x{:02x}'.format(i)) # string
"""
输出:
output1: bytes utf-8
...
125 : b'}'
126 : b'~'
127 : b'\x7f'
128 : b'\xc2\x80'
129 : b'\xc2\x81'
130 : b'\xc2\x82'
131 : b'\xc2\x83'
...
output2: bytes
...
125 : b'}'
126 : b'~'
127 : b'\x7f'
128 : b'\x80'
129 : b'\x81'
...
output3: string
...
126 : \x7e
127 : \x7f
128 : \x80
129 : \x81
130 : \x82
131 : \x83
...
"""
【 在 callmebbser 的大作中提到: 】
: c:\python
: Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64
: bit (AMD64)] on win32
: ...................
--
FROM 123.120.97.*