Easy Tutorial
❮ Python Func Ord Python Att List Pop ❯

Python math.log2() Method

Python math Module

The math.log2(x) method in Python returns the logarithm of x to the base 2.

Syntax

The syntax for the math.log2() method is as follows:

math.log2(x)

Parameter:

Return Value

Returns a float, representing the natural logarithm of a number to the base 2.

Example

The following example returns the natural logarithm of a number to the base 2:

# Import math package
import math

# Print the natural logarithm of a number to the base 2
print(math.log2(2.7183))
print(math.log2(2))
print(math.log2(1))

Output:

1.4427046851812222
1.0
0.0

Python math Module

❮ Python Func Ord Python Att List Pop ❯