is it possible to overload operator "^"?

D

dmitrey

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

Gary Herron

dmitrey said:
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.
 
D

Diez B. Roggisch

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

Did you read the link I gave you for your last question?

It shows __xor__ as special method.

Diez
 
D

dmitrey

the operator precedence will seem wrong
So, are there any ways to change operator precedence (for my class)?

To Diez:
yes, but I haven't paid attention to xor. BTW the url is currently
unavailable (Network Timeout. The server at docs.python.org is taking
too long to respond.).
 
A

Aahz

To Diez:
yes, but I haven't paid attention to xor. BTW the url is currently
unavailable (Network Timeout. The server at docs.python.org is taking
too long to respond.).

www.python.org is currently having hardware problems
--
Aahz ([email protected]) <*> http://www.pythoncraft.com/

"...string iteration isn't about treating strings as sequences of strings,
it's about treating strings as sequences of characters. The fact that
characters are also strings is the reason we have problems, but characters
are strings for other good reasons." --Aahz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top