Hello I was trying to compare two tuples in python using the cmp() function But there was an error wich is the following:
NameError: name 'cmp' is not defined
my Code:
myStupidTup = ("test",10,"hmm",233,2,"am long string")
mySmartTup = ("test",10,233,2)
print(cmp(myStupidTup, mySmartTup))
The
cmpfunction is only inPython 2.x. As mentioned in the official Python documentation:The
cmpequivalent inPython 3.xis:Note: Your tuples (
myStupidTupandmySmartTup) don't support comparison. You will get aTypeErrorif you run it:TypeError: '>' not supported between instances of 'str' and 'int'