[Python-ideas] Why no sign function?
Adam Olsen
rhamph at gmail.com
Mon Apr 26 23:34:50 CEST 2010
On Mon, Apr 26, 2010 at 15:12, cool-RR <cool-rr at cool-rr.com> wrote:
> This was probably discussed a lot. Why is there no simple `sign` function in
> Python, like in the math module or something? I mean one that tells you the
> sign of a number.
There is one. Python 2.6 added math.copysign(). However, it's
intended to deal with float peculiarities such as negative 0, so it's
a little obtuse. Most code, such as that using integers, should just
use "if x > 0:".
More information about the Python-ideas
mailing list