Phương thức Python math.copysign()
Ví dụ
Trả về giá trị của tham số thứ nhất và dấu của tham số thứ hai:
#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))
Hãy tự mình thử »Định nghĩa và cách sử dụng
Phương thức math.copysign()
trả về một số float bao gồm giá trị của tham số đầu tiên và dấu (+/-) của tham số thứ hai.
Cú pháp
math.copysign( x , y )
Giá trị tham số
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 |
Chi tiết kỹ thuật
Giá trị trả về: | Giá trị float , bao gồm giá trị của tham số đầu tiên và dấu của tham số thứ hai |
---|---|
Phiên bản Python: | 2.6 |