python 十六进制字符串中 0x 和 \x 的含义?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16903192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Meaning of 0x and \x in python hex strings?
提问by TheMeaningfulEngineer
I'm doing some binary operations which are often shown as hex-es. I have seen both the 0xand \xas prefixes.
我正在做一些通常显示为十六进制的二进制操作。我已经看到了0x和\x作为前缀。
In which case is which used?
在什么情况下使用?
采纳答案by John La Rooy
0xis used for literal numbers. "\x"is used inside strings to represent a character
0x用于文字数字。"\x"用在字符串内部来表示一个字符
>>> 0x41
65
>>> "\x41"
'A'
>>> "\x01" # a non printable character
'\x01'
回答by Euler
0x follows number, means HEX number
0x 跟在数字后面,表示十六进制数字
\x follows number, means HEX ascii characters
\x 跟随数字,表示十六进制 ascii 字符
check it here: ascii table
在这里检查: ascii表

