Unary plus operator and __pos__
Erik Max Francis
max at alcyone.com
Mon Sep 27 07:10:18 CEST 2004
Carlos Ribeiro wrote:
> Now I'm curious about the operator itself. Why is the unary plus
> operator associated with the __pos__ magic method? I' can't see a
> relation here, and I could not find much info (although I haven't
> really looked very hard :-)
> Anyone knows why is it so?
Unary plus is __pos__ for positive, unary minus is __neg__ for negative.
The unary plus operator, I'm sure, is a holdover from C. Since the
unary plus operator is a no-op for normal numeric values, I would be
hesitant to use it to mean something else; I'm a firm believer in
careful use of operator overloading, prefering to do so hopefully only
when the meaning is apparent from conventional operator usage. Since
unary + is a no-op, I don't think it would be a great idea to use it to
mean something vastly different, like "add a fact to the database." But
to each his own.
__ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
\__/ But the system has no wisdom / The Devil split us in pairs
-- Public Enemy
More information about the Python-list