Meaning of 0x and \x in python hex strings?

后端 未结 2 1408
隐瞒了意图╮
隐瞒了意图╮ 2020-12-24 07:41

I\'m doing some binary operations which are often shown as hex-es. I have seen both the 0x and \\xas prefixes.

In which case is which used

2条回答
  •  有刺的猬
    2020-12-24 07:54

    0x is used for literal numbers. "\x" is used inside strings to represent a character

    >>> 0x41
    65
    >>> "\x41"
    'A'
    
    >>> "\x01" # a non printable character
    '\x01'
    

提交回复
热议问题