Search code examples
pythoncomparison

Supplement for std::less in Python


I am a Python noob, but with good C++ experience. I am trying to write some code, where I would like to use < and > functions based on some conditions.

The best way to do it, seemed like making a function pointer and initializing it based on some conditions. I know I can write my own less and greater than functions. And no, a simple Google search doesn't tell you the answer.

But, is there a predefined function in Python, like std::less and std::greater?


Solution

  • As, C.Nivs, pointed in comments this can be done by using operator in Python.

    https://docs.python.org/3/library/operator.html