Python copysign function

Python copysign(x,y) function returns -x if y<0 and x if y>0. In other words, x copied the sign of y. It's a method of math module.

>>> import math
>>> math.copysign(0.2,-3)
-0.2
>>> math.copysign(0.2,-3)
0.2
>>> math.copysign(-54,3)
54.0
>>> math.copysign(-54,-3)
-54.0


















endmemo.com © 2024  | Terms of Use | Privacy | Home