-5

Can someone explain to me what is happening here?

>>> [] > 0
True
>>> [] > 0.1
True
>>> [] < 0
False
>>> [] < 0.1
False
>>> [] > 'string'
False
>>> [] < 'string'
True

Why and how does this work?

Matthias
  • 12,873
  • 6
  • 42
  • 48
drunk user
  • 65
  • 1
  • 9

1 Answers1

0

So you are using Python2, where you can compare between list and strings and numbers. This helps to sort them out.

Python2

   [0]>1
=> True

However since Python3 this has been removed.

Python3

   [0]>1
Traceback (most recent call last):
  File "python", line 1, in <module>
TypeError: unorderable types: list() > int() 

Hope that explains, why list has been made to be greater than number is purely subjective and depends on the creators.

garg10may
  • 5,794
  • 11
  • 50
  • 91