ching
answered Aug 9 '21 00:00
Lets see how operator. gt() or < react with list
what happen if we pass two lists in operator. gt()
import operator
x=[10,10]
y=[1.10]
print(operator.gt(x,y))
print(x>y)
it will print True both of time,
operator.gt(x,y) = True
x>y=True
as you can see above i made two lists, x had higher values than y but operator. gt() and >(greater than the operator) only compare the first value of lists, not others
so above it prints True in any case where the first value of list , x is greater than the first value of y list
x=[10,0]
y=[1.10]
print(operator.gt(x,y))
so it still prints True because only compare the first value of two lists
what happens if we pass one parameter is an integer and the other is a list in the operator. gt() ?
Let's see, in the below code we passing one is an integer and the second is list
import operator
x=10
y=[1.10]
print(operator.gt(x,y))
it will show you the following error :
TypeError: '>' not supported between instances of 'int' and 'list'