Phương thức toán học Python.log2 ()
Thí dụ
Tìm logarit cơ số 2 của các số khác nhau
# Import math Library
import math
# Return the base-2 logarithm
of different numbers
print(math.log2(2.7183))
print(math.log2(2))
print(math.log2(1))
Định nghĩa và Cách sử dụng
Phương math.log2()
thức trả về logarit cơ số 2 của một số.
Cú pháp
math.log2(x)
Giá trị tham số
Parameter | Description |
---|---|
x | Required. Specifies the value to calculate the logarithm for. If the value is 0, or a negative number, it returns a ValueError. If the value is not a number, it returns a TypeError |
Chi tiết kỹ thuật
Giá trị trả lại: | Một float giá trị, đại diện cho logarit cơ số 2 của một số |
---|---|
Phiên bản Python: | 3,3 |