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
cmp
function is only inPython 2.x
. As mentioned in the official Python documentation:The
cmp
equivalent inPython 3.x
is:Note: Your tuples (
myStupidTup
andmySmartTup
) don't support comparison. You will get aTypeError
if you run it:TypeError: '>' not supported between instances of 'str' and 'int'