Python Language Operator module Operators as alternative to an infix operator

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


For every infix operator, e.g. + there is a operator-function (operator.add for +):

1 + 1
# Output: 2
from operator import add
add(1, 1)
# Output: 2

even though the main documentation states that for the arithmetic operators only numerical input is allowed it is possible:

from operator import mul
mul('a', 10)
# Output: 'aaaaaaaaaa'
mul([3], 3)
# Output: [3, 3, 3]

See also: mapping from operation to operator function in the official Python documentation.

Got any Python Language Question?