Python Tutorial Python Advanced Python References Python Libraries

Python math - log2() Function



The Python math.log2() function returns the base-2 logarithm of a given number.

Syntax

math.log2(x)

Parameters

x Required. Specify the number.

Return Value

Returns the base-2 logarithm of a given number.

Example:

In the example below, log2() function is used to calculate the base-2 logarithm of a given number.

import math

print(math.log2(2))
print(math.log2(10))
print(math.log2(64))

The output of the above code will be:

1.0
3.321928094887362
6.0

❮ Python Math Module