Using an operator to add in Python

前端 未结 5 2175
隐瞒了意图╮
隐瞒了意图╮ 2021-01-06 13:35

Consider:

operator.add(a, b)

I\'m having trouble understanding what this does. An operator is something like +-*/, so what doe

5条回答
  •  无人及你
    2021-01-06 13:46

    It does the same, it's just a function version of the operator in the Python operator module. It returns the result, so you would just it like this:

    result = operator.add(a, b)
    

    This is functionally equivalent to

    result = a + b
    

提交回复
热议问题