Thursday, 22 August 2013

Viewing a list of all python operators via the interpreter?

Viewing a list of all python operators via the interpreter?

Say I've just implemented some class in Python and want to overload say
the '-' operator, but can't remember if I need to use __subtract__,
__minus__, or in fact the correct answer __sub__. Is there a quick way to
find this out via the interpreter? I tried simple things like help(-) but
no success.
There's plenty of online resources to give the definitive list of
available operators, but I'm looking for a quick offline method.
For common operators one quickly memorizes them, but some lesser used ones
often need looking up.

No comments:

Post a Comment