Operator module vs built-in operators

The operator module docs say that the operator module “exports a set of efficient functions…”, but those functions call the built-in operators under the hood. My question is, how are they more efficient then?

There’s two versions of the operator module in CPython. You probably found the pure Python implementation, but if you look at the bottom you’ll see it then imports a C implementation of the module, which instead directly performs the operation. The pure Python version isn’t intended for CPYthon itself, instead it’s provided for the benefit of other implementations like PyPy or MicroPython to be able to use directly.

2 Likes