🌐
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
koshurai.medium.com › infinity-in-python-156b55ae0c54
Infinity in Python. In Python, the value float("inf")… | by KoshurAI | Medium
December 31, 2022 - For example: x = float("inf") y = 1 print(x > y) # True print(x + y) # inf print(x - y) # inf print(x * y) # inf print(x / y) # inf · If you need to perform arithmetic operations with infinity, you can use the float("inf") and float("-inf") values as sentinel values to represent infinity in your code...
Discussions

What is the point of float('inf') in Python? - Stack Overflow
The -sys.maxsize - 1 is used for ... as -ve infinity. ... I don't recommend this, as sys.maxsize refers to the maximum size for sequence indexing, but other numbers could be larger; on a 64-bit platform both 2.0**100 and 2**100 will exceed this (the latter due to Python supporting arbitrary-precision ints by default). 2022-08-30T08:37:11.01Z+00:00 ... Save this answer. ... Show activity on this post. float('inf') can ... 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
float('inf') is bad practice
math.inf is there for you, and I prefer it over float('inf') in most if not all cases. More on reddit.com
🌐 r/Python
72
79
April 15, 2024
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-infinity
Python infinity (inf) - GeeksforGeeks
Infinity represents a value that is greater than every finite number or smaller than every finite negative number. Python does not provide an integer type for infinity, but it supports positive and negative infinity through floating-point values and other numeric types.
Published: 2 weeks ago
🌐
Note.nkmk.me
note.nkmk.me › home › python
Infinity (inf) in Python | note.nkmk.me
August 11, 2023 - print(float('inf')) # inf print(float('infinity')) # inf print(float('INF')) # inf print(float('INFinity')) # inf ... Floating-point numbers exceeding the maximum value of float are automatically treated as inf. import sys f_inf_num = ...
🌐
Kodeclik
kodeclik.com › inf-in-python
Infinity in Python: float('inf'), math.inf, and Algorithms
June 16, 2025 - Here’s an example of how you might use infinity to initialize a minimum value when searching through a list: # A list of numbers numbers = [4, 1, 3, 7, 2] # Initialize min_value to positive infinity min_value = float('inf') for number in numbers: ...
🌐
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 - Read for free: https://allwin-raju.medium.com/infinity-in-python-b1d8e03803aa?sk=b935756efd097f1f644f7064f7512494 · pos_inf = float('inf') neg_inf = float('-inf') print(pos_inf) # inf print(neg_inf) # -inf
🌐
W3Schools
w3schools.com › python › ref_math_inf.asp
Python math.inf Constant
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... # 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.
🌐
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.
Find elsewhere
🌐
Python
docs.python.org › 3.2 › library › functions.html
2. Built-in Functions — Python v3.2.6 documentation
sign ::= "+" | "-" infinity ::= ... point literals. Case is not significant, so, for example, “inf”, “Inf”, “INFINITY” and “iNfINity” are all acceptable spellings for positive infinity....
🌐
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.
🌐
STechies
stechies.com › python-infinity
Infinity in Python - Represent an Infinite Number in Python
import math # Define positive infinity number ptive_inf = float('inf') # Define negative infinity number ntive_inf = float('-inf') print('Positive infinity equal to Negative infinity: ',ptive_inf == ntive_inf)
🌐
Scaler
scaler.com › home › topics › how to represent infinity in python?
How to Represent Infinity in Python? - Scaler Topics
May 4, 2023 - There are multiple ways of representing infinity in Python, let's understand them one by one. Method 1 : Using float(‘inf’) and float(‘-inf’)
🌐
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 - When performing mathematical operations involving infinity, we can encounter two scenarios: operations with two infinite values and operations with one infinite value and one finite value. int1 = float('inf') int2 = float('-inf') print("Adding ...
🌐
Designcise
designcise.com › web › tutorial › how-to-represent-infinity-in-python
How to Represent "Infinity" in Python? - Designcise
November 21, 2023 - print(float('-inf') < -100) # True print(float('-inf') < 0) # True print(float('-inf') < 100) # True · You can use positive and negative infinity as you would any other value in Python. For example:
🌐
Finxter
blog.finxter.com › home › learn python blog › python infinity
Python Infinity – Be on the Right Side of Change
September 16, 2020 - The following example illustrates this concept : value = float('inf') print('Result of Addition : ',value + 15) print('Result of Subtraction : ',value - 15) print('Result of Multiplication : ',value * 15) print('Result of Division : ',value / 15) ...
🌐
Medium
medium.com › @ryan_forrester_ › infinity-in-python-complete-guide-ad7f108adf15
Infinity in Python: Complete Guide | by ryan | Medium
October 24, 2024 - inf = float('inf') ninf = float('-inf') # Basic comparisons print(inf > 999999999999999) # Output: True print(ninf < -999999999999999) # Output: True # Infinity with itself print(inf == inf) # Output: True print(inf > inf) # Output: False print(inf ...
🌐
Codemia
codemia.io › home › knowledge hub › how to represent an infinite number in python?
How to represent an infinite number in Python? | Codemia
September 23, 2025 - Mixing Decimal and float values carelessly, causing implicit conversion confusion. Representing infinity in Python is straightforward with float('inf') and float('-inf'), and these values are ideal for sentinel initialization in many algorithms. The reliability work is in edge handling: check ...
🌐
Finxter
blog.finxter.com › home › learn python blog › setting a python float to infinity: 5 practical methods
Setting a Python Float to Infinity: 5 Practical Methods - Be on the Right Side of Change
February 25, 2024 - ... In this example, the variable infinity is assigned the result of division by zero. This results in the value inf for infinity, which Python allows for floating-point divisions but would raise an exception for integer divisions.