Home »
Python
math.inf constant with example in Python
Python math.inf constant: Here, we are going to learn about the math.inf constant of math module with example in Python.
Submitted by IncludeHelp, on April 19, 2019
Python math.inf constant
math.inf constant is a predefined constant, which is defined in the math module, it returns a floating-point positive infinity (which is equivalent to float('inf')).
-math.inf can be used to find floating-point negative infinity (which is equivalent to float('-inf')).
Note: math.inf constant is available from Python 3.5
Syntax of math.inf constant:
math.inf
Return value: float – that is the value of positive infinity.
Example:
Input:
print(math.inf)
Output:
inf
Python code to demonstrate example of math.inf constant
# python code to demonstrate example of
# math.inf constant
# importing math module
import math
# printing value of infinity
print("value of positive infinity = ", math.inf)
print("value of negative infinity = ", -math.inf)
Output
value of positive infinity = inf
value of negative infinity = -inf
Reference: Python math library