Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


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 below example, 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

5