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

后端 未结 6 1140
栀梦
栀梦 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:44

    Sure, go ahead and remove them.

    hex(bignum).rstrip("L").lstrip("0x") or "0"
    

    (Went the strip() route so it'll still work if those extra characters happen to not be there.)

提交回复
热议问题