is it possible to overload operator "^"?

Gary Herron gherron at islandtraining.com
Sat Aug 8 05:02:19 EDT 2009


dmitrey wrote:
> hi all,
> is it possible to overload operator "^"? (AFAIK __pow__ overloads **
> instead of ^)
> Thank you in advance, D.
>   

The ^ operator is not an exponentiation, but rather the xor operator.  
Thus you can override it with the __xor__ method.

Beware, if you are thinking of ^ as an exponentiation like operator, the 
operator precedence will seem wrong.




More information about the Python-list mailing list