How to convert an integer to hexadecimal without the extra '0x' leading and 'L' trailing characters in Python?

后端 未结 6 1120
栀梦
栀梦 2021-02-18 14:23

I am trying to convert big integer number to hexadecimal, but in result I get extra \"0x\" in the beginning and \"L\" at the and. Is there any way to remove them. Thanks. The nu

6条回答
  •  一向
    一向 (楼主)
    2021-02-18 14:47

    The 0x is literal representation of hex numbers. And L at the end means it is a Long integer.

    If you just want a hex representation of the number as a string without 0x and L, you can use string formatting with %x.

    >>> a = 44199528911754184119951207843369973680110397
    >>> hex(a)
    '0x1fb62bdc9e54b041e61857943271b44aafb3dL'
    >>> b = '%x' % a
    >>> b
    '1fb62bdc9e54b041e61857943271b44aafb3d'
    

提交回复
热议问题