Python – Find Base-2 Logarithm – log2() Function with Examples

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:


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.



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