Print a variable in hexadecimal in Python

后端 未结 6 1399
盖世英雄少女心
盖世英雄少女心 2021-02-05 09:17

I\'m trying to find a way to print a string in hexadecimal. For example, I have this string which I then convert to its hexadecimal value.

my_string = \"deadbeef         


        
6条回答
  •  遇见更好的自我
    2021-02-05 09:51

    Another answer with later print/format style is:

    res[0]=12
    res[1]=23
    print("my num is 0x{0:02x}{1:02x}".format(res[0],res[1]))
    

提交回复
热议问题