math.log2(x)
Where x
is the number whose base-2 logarithm we want.
import math
print(math.log2(4))
print(math.log2(8))
print(math.log2(64))
print(math.log2(100))
The math.log2 function is shorthand for math.log() function with 2 as the base i.e math.log(x, 2)
import math
print(math.log2(50))
print(math.log(50, 2))
A ValueError
is raised if the value given as argument is negative.
import math
math.log2(-1)