How to Represent an Infinite Number in Python?
To represent an infinite number you need to define a specific rule. For example, the infinite number in the examples of this article is represented as a string developed in the Python programming language. If you have any questions or suggestions kindly use the comment section and help us build a better article.
python infinite value
test = float("inf") In Python 3.5, you can do: import math test = math.inf
infinity in python
# Defining a positive infinite integer positive_infnity = float('inf') print('Positive Infinity: ', positive_infnity) # Defining a negative infinite integer negative_infnity = float('-inf') print('Negative Infinity: ', negative_infnity)
python math negative infinity
# Import math Library import math # Print the positive infinity print (math.inf) # Print the negative infinity print (-math.inf)
test = float("inf")
python set negative infinity
# Define Negative infinity number ntive_inf = float('-inf') print('Negative Infinity: ',ntive_inf)
float inf in python
When we are trying to represent infinite numbers in python, we use isinf() function because it returns true when the value is infinite.