-1

I make a list or tuple including some binary or hex numbers in Python.

lst = [0x2ad2, 0xffcc00, 0xfcfc2]
tup = (0x2ad2, 0xffcc00, 0xfcfc2)
print(lst)
print(tup)

But Python turns them to decimal. I want them to stay in their original number system. is there a method or function for that? How can I prevent that?

(10962, 16763904, 1036226)
[10962, 16763904, 1036226]

  • 1
    `0x` is an _alternative syntax_ to write numbers. The result is a number. Not exactly what you typed, because *a number* doesn't remember what format it was created with. It only has its numeric value. Which is printed as decimal by default. – deceze Aug 23 '23 at 05:04
  • If you don't care about doing any numeric operations with them, then use strings instead of numbers. If you do want them to be actual numbers, but print them in hex notation, then you need to format them to hex while printing. – deceze Aug 23 '23 at 05:20
  • thank you. how can I format the whole list into hex ? – Mo Karbasi Aug 23 '23 at 05:24
  • I have already added an apropos duplicate question about that above… – deceze Aug 23 '23 at 05:25

0 Answers0