Python – Checking if x>y without if statement

if statementpython

In Python, is it possible to check whether x>y without using the if statement?

Best Answer

There are a variety of ways to go about this:

print "yes" if x > y else "no"

or:

print ["no", "yes"][x > y]

or:

print x > y and "yes" or "no"

(at least, this is what my mind-reading powers think that you're doing)