operator module functions

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Oct 7 21:41:54 EDT 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:

operator.__add__;
operator.__sub__;
operator.__mul__;

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?


-- 
Steven




More information about the Python-list mailing list