-1

I came up with this comparison issue in python in binary values which is mentioned here in the image.

Python IDLE Screenshot

What are the possible reasons for returning "True" to the comparison between bin(1538)<bin(5138) since numerical value and binary digit length of the two binary values are contradictory to the output in python? Are there any specific comparison rules in python when it comes to the comparisons between binary values generated by bin() function (python default function) or are they similar as normal number comparisons?

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
alfalfa
  • 1
  • 2
  • [put code in questions as text](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question) copy and paste the code above in question as text, not as an image. – Ahmed AEK Sep 24 '22 at 11:39
  • Please don't post code as images. Use a code block instead – Thomas Weller Sep 24 '22 at 11:39

1 Answers1

1

because you are comparing two strings and the first string is "larger" than the second one...

try this as an example:

x = bin(1538)
print(x)
print(type(x))

y = bin(5138)
print(y)
print(type(y))

returns this:

0b11000000010
<class 'str'>
0b1010000010010
<class 'str'>
D.L
  • 4,339
  • 5
  • 22
  • 45