It acts as an unbounded upper value for comparison. This is useful for finding lowest values for something. for example, calculating path route costs when traversing trees.

e.g. Finding the "cheapest" path in a list of options:

>>> lowest_path_cost = float('inf')
>>> # pretend that these were calculated using some worthwhile algorithm
>>> path_costs = [1, 100, 2000000000000, 50]
>>> for path in path_costs:
...   if path < lowest_path_cost:
...     lowest_path_cost = path
...
>>> lowest_path_cost
1

if you didn't have float('Inf') available to you, what value would you use for the initial lowest_path_cost? Would 9999999 be enough -- float('Inf') removes this guesswork.

Answer from user559633 on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-infinity
Python infinity (inf) - GeeksforGeeks
Python does not provide an integer type for infinity, but it supports positive and negative infinity through floating-point values and other numeric types. The float() constructor can create positive and negative infinity. ... positive_infinity ...
Published: 1 week ago
Discussions

Number theory discussion regarding floats, ints and NaN/Inf
That’s right. Heh, so NaN is, pretty literally, “not a number”, but infinity is ? Math-wise at least that doesn’t make sense, infinity has a meaning as a notation in the context of limits, but it’s neither a number nor even a value. Python-wise, we already treat nan and the infs as ... More on discuss.python.org
🌐 discuss.python.org
18
1
April 12, 2023
How do I type a floating point infinity literal in python - Stack Overflow
How do I type a floating point infinity literal in python? I have heard inf = float('inf') is non portable. Thus, I have had the following recommended: inf = 1e400 Is either of these standar... More on stackoverflow.com
🌐 stackoverflow.com
What does stating a variable as float('inf') do?
float('inf') is infinity. You need that because the minimum of a positive number and zero is always zero, so you are finding the minimum value, you are always returning zero. Though this code is way more complicated than needed. Do you see how you could do this without a for loop? More on reddit.com
🌐 r/learnpython
10
3
August 2, 2020
What's different between Decimal and Floating point numbers in Python?
Integers (int type) are "whole numbers", without the fractional part, eg. 10. You use this type when the value is always an integer, e.g. a counter. Floating point numbers (float type) can have fractional part, e.g. 10.1234. They are stored using the closest representation in binary notation. Most numbers cannot be represented accurately, so they are slightly off. You use float for most mathematical calculations involving fractional numbers. Decimal numbers (Decimal type in Python) are used to represent floating point numbers accurately, with a defined precision (a defined number of places after decimal point). They are represented with two integer numbers, one for the integer part and one for the fractional part. For example. 10.1234 is stored as (10, 1234). Decimal type is required when fractional numbers must be represented accurately, with defined precision. The most notable example is financial calculations. Using float type you may get a result of a financial operation as 1010.123456$. But money is expressed with at most two decimal places. What does 0.123456$ mean? You can round it to 1010.12$, but then what happens with the remaining 0.003456$? Some "smart" programmers used that to their advantage in the past and they made a lot of money (which they eventually had to give back). So, for money calculations, you should use Decimal type. A good explanation of the Decimal type is in the documentation: https://docs.python.org/3/library/decimal.html More on reddit.com
🌐 r/learnpython
6
6
March 5, 2021
🌐
FavTutor
favtutor.com › blogs › infinity-python
Infinity in Python (float('inf'), math.inf) | FavTutor
July 21, 2026 - In Python, infinity is a float value written as float("inf").
🌐
Medium
medium.com › @c.fedesna › float-inf-in-python-c942e28340da
Float('inf') in Python - by C. Fedesna
November 21, 2023 - >>> print(math.inf) inf >>> print(float('inf')) inf ... Which… it’s weird to think of infinity matching infinity except when arguing with a child about who loves who more.
🌐
W3Schools
w3schools.com › python › ref_math_inf.asp
Python math.inf Constant
# Import math Library import math # Print the positive infinity print (math.inf) # Print the negative infinity print (-math.inf) Try it Yourself » · The math.inf constant returns a floating-point positive infinity.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Infinity (inf) in Python | note.nkmk.me
August 11, 2023 - There are several ways to create inf, such as using the float() function, the math module, or the NumPy library. You can create inf by specifying the string 'inf' or 'infinity' to float().
Find elsewhere
🌐
CodeGym
codegym.cc › java blog › learning python › infinity in python: mastering the infinite
Infinity in Python: Mastering the Infinite
August 13, 2024 - Python provides a straightforward way to represent infinity using the float() function. To represent positive infinity, you simply use: positive_infinity = float('inf') print(positive_infinity) # Output: inf
🌐
Kodeclik
kodeclik.com › inf-in-python
Infinity in Python: float('inf'), math.inf, and Algorithms
June 16, 2025 - In Python, you can represent (positive) infinity using the special floating-point value float('inf'). Since Python 3.5, you can also use math.inf from the standard library's math module.
🌐
Medium
koshurai.medium.com › infinity-in-python-156b55ae0c54
Infinity in Python. In Python, the value float("inf")… | by KoshurAI | Medium
December 31, 2022 - In Python, the value float("inf") represents positive infinity, and float("-inf") represents negative infinity.
🌐
Medium
allwin-raju.medium.com › infinity-in-python-b1d8e03803aa
Infinity in Python. In Python, you can represent infinity… | by Allwin Raju | Medium
February 5, 2025 - In Python, you can represent infinity using float('inf'). It can be used in mathematical operations, comparisons, and algorithms that…
🌐
Python Central
pythoncentral.io › infinity-in-python-how-to-represent-and-use-infinite-numbers
Infinity In Python: How to Represent (And Use!) Infinite Numbers | Python Central
June 27, 2023 - Let's quickly see them in action: The first method involves utilizing the float() function to represent positive and negative infinity. To represent positive infinity, you can pass 'inf' as the argument, while '-inf' represents negative infinity.
🌐
Python.org
discuss.python.org › python help
Number theory discussion regarding floats, ints and NaN/Inf - Python Help - Discussions on Python.org
April 12, 2023 - That’s right. Heh, so NaN is, pretty literally, “not a number”, but infinity is ? Math-wise at least that doesn’t make sense, infinity has a meaning as a notation in the context of limits, but it’s neither a number nor even a value. Python-wise, we already treat nan and the infs as a special thing, in the floor, ceil, round and int functions.
🌐
GitHub
github.com › kvesteri › infinity
GitHub - kvesteri/infinity: All-in-one infinity value for Python. Can be compared to any object. · GitHub
All-in-one infinity value for Python. Can be compared to any object. Python has float('inf') and float('-inf'). However these simply represent floating point infinity values.
Author: kvesteri
🌐
Codecademy
codecademy.com › docs › python › math module › math.isinf()
Python | Math Module | math.isinf() | Codecademy
September 4, 2024 - Learn the basics of Python 3.13, one of the most powerful, versatile, and in-demand programming languages today. With CertificateWith Certificate · Beginner Friendly.Beginner Friendly24 hours24 hours · math.isinf(x) x: The number to be checked for infinity. The following example demonstrates how to use the math.isinf() function: import math · print(math.isinf(float('inf'))) # Positive infinity ·
🌐
Finxter
blog.finxter.com › home › learn python blog › python infinity
Python Infinity – Be on the Right Side of Change
September 16, 2020 - Summary: Python Infinity is an ... value in a given code. The numerous ways of using Python infinity are: Using float('Inf') and float('-Inf') Using the math module. ......
🌐
Scaler
scaler.com › home › topics › how to represent infinity in python?
How to Represent Infinity in Python? - Scaler Topics
May 4, 2023 - We can use the float() function in Python to represent the positive infinity and negative infinity. For positive infinity, we need to pass 'inf' to the float() function and for negative infinity, we need to pass '-inf' to the float() function.
🌐
TutorialsPoint
tutorialspoint.com › How-can-I-represent-an-infinite-number-in-Python
How can I represent an infinite number in Python?
November 9, 2022 - Use the float('inf') to get a positive infinite integer value and create a variable to store it.