In my python CS class at school, we were given a true or false question as follows.
A comparison function returns either True or False.
When originally answering I thought about two things. First, a function as follows (what I thought was a comparison function) returns true or false.
def comparison(valOne,valTwo):
return valOne<valTwo
Now, I know this isn't a comparison function, but a function with an operator. In addition, I thought of another type of function when answering.
def someoneHasOne(scoreOne,scoreTwo):
return scoreOne==15 or scoreTwo==15
From what I know, this is a comparison function.
So, thinking of those two things, I marked this as
True
.
However, the correct answer, according to the teacher, was False
. After the answer was marked wrong, I started to do some research. I found this about the operator module that has comparison functions that return True
or False
My main question is, am I right (the answer is
True
)? Or is my CS teacher right (the answer isFalse
)?
<=>
for this. In Python 2, thecmp
function does the same thing. For a three-way comparison, True/False clearly doesn't suffice. More common is to return -1, 0, 1. In languages with good sum types like Haskell, you're more likely to see something likeLT | EQ | GT
.strcmp
for C,<=>
andcmp
for perl,compareTo
fromComparable
or theComparator
in Java,IComparable.CompareTo
andComparison<T>
in C#, theOrdered
trait withcompare
in scala,(compare x y)
in Scala...