Change if conditon dynamic ? (python)
<p>Hey guys i want to change the if condition in a function dynamic.</p>

<pre><code>def func(&lt;):
     if y&lt;x:
        return x

def func(=):
         if y=x:
            return x
</code></pre>

<p>i want just the condition changed, any ideas?</p>

<p>You can not use the operators like <code>=</code> and <code>&lt;</code> directly. But you can import them from <code>operator</code>:</p>

<pre><code>from operator import le, eq

def func(op):
    if op(x, y):
        return x

func(le)       # â x &lt; y
func(eq)       # â x == y
</code></pre>

<p>BTW the comparison operator is <code>==</code> not <code>=</code>.</p>

python function python-3.x if-statement