📜  通过参数发送运算符 python 代码示例

📅  最后修改于: 2022-03-11 14:45:23.214000             🧑  作者: Mango

代码示例1
import operator

# '>': operator.gt
# '<': operator.lt,
# '>=': operator.ge,
# '<=': operator.le,
# '=': operator.eq

get_truth(1.0, operator.gt, 0.0)

...

def get_truth(inp, relate, cut):    
    return relate(inp, cut)
    # you don't actually need an if statement here