Why does 0x1=1 in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

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~

22nd May 2021, 1:58 AM
This is Sparta
This is Sparta - avatar
2 Answers
+ 5
0x is the prefix for literal hexadecimal... 0x1 (hexa) == 1 (decimal) 0xf (hexa) == 15 (decimal) 0xff (hexa) == 255 (decimal)
22nd May 2021, 2:02 AM
visph
visph - avatar
+ 1
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!
22nd May 2021, 2:12 AM
This is Sparta
This is Sparta - avatar