Is there any way to have Python operators line “==” and “>” return ints instead of bools. I know that I could use the int function (int(1 == 1)) or add 0 ((1 == 1) + 0) but I was wondering if there was an easy way to do it. Like when you want division to return floats you could type from __future__ import division. Is there any way to do this with operators returning ints? Or could I make a class extending __future__._Feature that would do what I want?
Is there any way to have Python operators line == and > return ints
Share
Based on your clarification, you might change your comparison operator to something like:
This will convert the boolean result of
>to1or0as you would like.Also, be careful about calling
stack.pop()twice in the same expression. You don’t know (for sure) what order the arguments will be evaluated in, and different implementations of Python may very well pop the arguments in a different order. You will need to use temporary variables: