Python math.copysign()メソッド
例
最初のパラメーターの値と2番目のパラメーターの符号を返します。
#Import math Library
import math
#Return the value of the first
parameter and the sign of the second parameter
print(math.copysign(4, -1))
print(math.copysign(-8, 97.21))
print(math.copysign(-43, -76))
定義と使用法
このmath.copysign()
メソッドは、最初のパラメーターの値と2番目のパラメーターの符号(+/-)で構成されるfloatを返します。
構文
math.copysign(x, y)
パラメータ値
Parameter | Description |
---|---|
x | Required. A number. The return will have the value of this parameter |
y | Required. A number. The return will have the sign (+/-) of this parameter |
技術的な詳細
戻り値: | 最初のパラメーターのfloat 値と2番目のパラメーターの符号で構成される値 |
---|---|
Pythonバージョン: | 2.62.6 |