log2()
function is used to find the the base-2 logarithm of x in Python for the given input(x – parameter).
Syntax of log2()
Function
The syntax of
log2()
function in Python is:
math.log2(x)
Parameters of log2()
Function in Python
x
– Where x
is any valid python number (positive or negative). This parameter is required.Note: If the
x
parameter is not a number, log2()
function will return an Error.
Compatibility
log2()
function is available and compatible with Python 3.3
and above versions. This function is a part of python standard math library.
Return Value of log2()
Function in Python
log2()
function returns the base-2 logarithm of x for the given input.
Python log2()
Function Example
# import math library import math print(math.log2(-0.2)) print(math.log2(0)) print(math.log2(0.2)) print(math.log2(77)) print(math.log2(-3677))
Output: