find the base 2 logarithm of a number in python

To find the base 2 logarithm of a number in python, you can use the math library's log2() function.

main.py
import math

num = 16
log_base_2 = math.log2(num)

print(log_base_2) # Output: 4.0
83 chars
7 lines

In the example code above, we imported the math library and assigned the number 16 to the variable "num". We then used the log2() function to calculate the base 2 logarithm of "num" and assigned it to the variable "log_base_2". Finally, we printed the value of "log_base_2" which is 4.0.

gistlibby LogSnag