Python math.log2() Method

❮ Math Methods


Example

Find the base-2 logarithm of different numbers

# Import math Library
import math

# Return the base-2 logarithm of different numbers
print(math.log2(2.7183))
print(math.log2(2))
print(math.log2(1))
Try it Yourself »

Definition and Usage

The math.log2() method returns the base-2 logarithm of a number.


Syntax

math.log2(x)

Parameter Values

Parameter Description
x Required. Specifies the value to calculate the logarithm for. If the value is 0, or a negative number, it returns a ValueError. If the value is not a number, it returns a TypeError

Technical Details

Return Value: A float value, representing the base-2 logarithm of a number
Python Version: 3.3

❮ Math Methods

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.