operator module functions

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Oct 8 03:41:54 CEST 2014

Every Python operator has a function version in the operator module:

operator + has function operator.add;
operator - has function operator.sub;
operator * has function operator.mul;

and so forth. Only, that's not quite right... according to the
documentation, the "official" functions are actually:


etc., with the underscore-less versions being provided as a convenience.

Was anyone aware of this? It came as a surprise to me.

Is there anyone who uses or prefers the dunder versions?


More information about the Python-list mailing list