How to create a unary operator?
Martin v. Löwis
loewis at informatik.hu-berlin.de
Tue Nov 5 13:29:34 EST 2002
"Joe Sixpack" <joe.sixpack at whoopie.com> writes:
> Is it possible to create a unary operator on a class object by
> redefining an existing operator symbol? If so, how?
You can implement existing unary operators, by means of special
methods (e.g. __neg__). You cannot add new operators to the language.
> For example, I'd like to create a new class, MyClass, and use the
> symbol '^' to call a method in that class. The '^' is a standard
> symbol in the domain of the problem that I'm working in, so I'd like
> to use that symbol instead of a different one, if at all possible.
Sorry, that's not possible. Use methods instead.
Regards,
Martin
More information about the Python-list
mailing list