Why does 0x1=1 in python | Sololearn: Learn to code for FREE!


Why does 0x1=1 in python

sorry that Im a beginner I tried---> print(0x1) in python , where x is a letter before y, then it output '1' (me:????) So what does that '0xk' meaning for , where k is a constant Cause the result of: print(1xk) will always be 'k' I'm just a little bit interesting about it Thx a lot if any help~

5/22/2021 1:58:19 AM

This is Sparta

2 Answers

New Answer


0x is the prefix for literal hexadecimal... 0x1 (hexa) == 1 (decimal) 0xf (hexa) == 15 (decimal) 0xff (hexa) == 255 (decimal)


Oic That's really a cool thing for me! I'm interested what to do if I want to turn from hexadecimal to decimal or turn from decimal to bincimal~ Thxxxxxxx!