One way to reliably get the limits of floating point formats is to construct the values from their binary representation with struct.

import struct
FLOAT_MAX = struct.unpack('>f', b'\x7f\x7f\xff\xff')
FLOAT_MIN = struct.unpack('>f', b'\xff\x7f\xff\xff')
MAX_DOUBLE = struct.unpack('>d', b'\x7f\xef\xff\xff\xff\xff\xff\xff')
MIN_DOUBLE = struct.unpack('>d', b'\xff\xef\xff\xff\xff\xff\xff\xff')
Answer from javidcf on Stack Overflow
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 3477283 โ€บ what-is-the-maximum-float-in-python
floating point - What is the maximum float in Python? - Stack Overflow
The maximum integer in Python 2 is available by calling sys.maxint. What is the maximum float or long in Python? See also: Maximum and Minimum values for ints.
Discussions

floating point - Python: Return max float instead of infs? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives ยท Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
๐ŸŒ stackoverflow.com
Python: Usable Max and Min values - Stack Overflow
And in Python 2.7 an empty tuple () is an infinite value: ... This shortcut is useful when one might sort a mixed list of ints and floats and want to have an absolute minimum and maximum to reference. More on stackoverflow.com
๐ŸŒ stackoverflow.com
how to get the max value if that is a float?
The error message sounds like you are giving max() function only 1 number... It can't find the max if you only give it one number... >>> max([1.5, 2763.2]) 2763.2 >>> max(1.5) Traceback (most recent call last): File "", line 1, in TypeError: 'float' object is not iterable More on reddit.com
๐ŸŒ r/learnpython
2
2
December 6, 2022
floating point - What is the range of values a float can have in Python? - Stack Overflow
Python uses double-precision floats, which can hold values from about 10 to the -308 to 10 to the 308 power. More on stackoverflow.com
๐ŸŒ stackoverflow.com
December 3, 2009
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Maximum and Minimum float Values in Python | note.nkmk.me
August 11, 2023 - In Python, the float type is a 64-bit double-precision floating-point number, equivalent to double in languages like C. This article explains how to get and check the range (maximum and minimum values) that float can represent in Python. In many environments, the representable range for float ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ What-is-the-maximum-value-of-float-in-Python
What is the maximum value of float in Python?
Let's see what happens when we ... print("OverflowError occurred!") ... Python's maximum float value is approximately 1.798 ร— 10308, accessible via sys.float_info.max....
๐ŸŒ
Programiz
programiz.com โ€บ swift-programming โ€บ library โ€บ double โ€บ maximum
Swift Double maximum() (With Examples)
Check leap year All Python Examples ... Swift Double squareRoot() Swift Set max() Swift Array max() Swift Double rounded() The maximum() method returns the maximum of the given two values....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ maximum-of-two-numbers-in-python
Find the Maximum of two numbers in Python - GeeksforGeeks
Python ยท a = 7 b = 3 print(max(a, b)) Output ยท 7 ยท Ternary conditional operator evaluates a condition and returns one of two values depending on whether the condition is true or false in a single expression. Python ยท a = 7 b = 3 print(a if a > b else b) Output ยท
Published: May 18, 2026
Find elsewhere
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ find maximum float value in python
Find Maximum Float Value in Python - Spark By {Examples}
May 31, 2024 - How to find the maximum float value in Python? You can find the maximum value of the float data type using the sys.float_info module or the finfo()
Top answer
1 of 3
16

For numerical comparisons, +- float("inf") should work.

It doesn't always work (but covers the realistic cases):

print(list(sorted([float("nan"), float("inf"), float("-inf"), float("nan"), float("nan")])))
# NaNs sort above and below +-Inf
# However, sorting a container with NaNs makes little sense, so not a real issue.

To have objects that compare as higher or lower to any other arbitrary objects (including inf, but excluding other cheaters like below), you can create classes that state their max/min-ness in their special methods for comparisons:

class _max:
    def __lt__(self, other): return False
    def __gt__(self, other): return True

class _min:
    def __lt__(self, other): return True
    def __gt__(self, other): return False

MAX, MIN = _max(), _min()

print(list(sorted([float("nan"), MAX, float('inf'), MIN, float('-inf'), 0,float("nan")])))
# [<__main__._min object at 0xb756298c>, nan, -inf, 0, inf, nan, <__main__._max object at 0xb756296c>]

Of course, it takes more effort to cover the 'or equal' variants. And it will not solve the general problem of being unable to sort a list containing Nones and ints, but that too should be possible with a little wrapping and/or decorate-sort-undecorate magic (e.g. sorting a list of tuples of (typename, value)).

2 of 3
11

You have the most obvious choices in your question already: float('-inf') and float('inf').

Also, note that None being less than everything and the empty tuple being higher than everything wasn't ever guaranteed in Py2, and, eg, Jython and PyPy are perfectly entitled to use a different ordering if they feel like it. All that is guaranteed is consistency within one running copy of the interpreter - the actual order is arbitrary.

๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ maximum of two numbers in python
Maximum of Two Numbers in Python - Spark By {Examples}
May 31, 2024 - How to find the maximum of two numbers in Python? You can create a program that takes two integers as input from the user and returns the maximum of the
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ maximum-of-two-numbers-in-python
Find Maximum of two numbers in Python - GeeksforGeeks
Using num[-1] accesses the maximum value. Since 7 is greater than 3, the list becomes [3, 7] and num[-1] returns 7. ... Practice with Python program examples is always a good choice to scale up your logical understanding and programming skills ...
Published: May 9, 2025
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how to get the max value if that is a float?
r/learnpython on Reddit: how to get the max value if that is a float?
December 6, 2022 -

Hi, I have calculated some values and now need the program to print which is the largest. The problem is that these numbers are floats and I get an error: TypeError: 'float' object is not iterable when using the max function. And I can't change it to int for example, because I need to include numbers after the comma. I would be really grateful if someone could help me.

๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ built-in โ€บ max
Python max()
Based on the values (rather than the dictionary's keys), the key having the maximum value is returned.
๐ŸŒ
Interview Kickstart
interviewkickstart.com โ€บ home โ€บ blogs โ€บ learn โ€บ max() function in python: syntax, parameters, and examples
max() Function in Python: Syntax, Parameters & Examples
April 1, 2026 - It determines the result by comparing values using the default > and < operators, and if there are multiple equal maximum values, it returns the first one it encounters. The Python max function is used in two common ways: you can pass multiple values directly, or you can pass a single iterable such as a list, tuple, or string.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Finding max value in a series of floats - Python Help - Discussions on Python.org
April 15, 2024 - I am trying to write code that takes a row of floats from a csv file, representing the average temperature in a given month over the course of 70 years, and returns the highest float value of them all. When I print the variable holding the float values, in this case val, I get something similar ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_max.asp
Python max() Function
Python Examples Python Compiler ... Interview Q&A Python Training ... The max() function returns the item with the highest value, or the item with the highest value in an iterable....
๐ŸŒ
Gurobi
support.gurobi.com โ€บ hc โ€บ en-us โ€บ community โ€บ posts โ€บ 13427628470673-Maximum-of-two-values
Maximum of two values โ€“ Gurobi Help Center
Hi. In my model coded in Python, after getting the optimal values of some variables, I built a mathematical expression to get a number, i.e. for i in I: y[i] = max(0, y[i-1]+ a*z[i-1]) Here z[i...