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
Finding max value in a series of floats
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 ... More on discuss.python.org
🌐 discuss.python.org
11
0
April 15, 2024
🌐
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 ...
🌐
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...
🌐
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....
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-max-function
Python - max() function - GeeksforGeeks
July 15, 2025 - Unlike the max() function of C/C++, the max() function in Python can take any type of object and return the largest among them. In the case of strings, it returns the lexicographically largest value.
🌐
Hyperskill
hyperskill.org › university › python › max-in-python
Python max() Function — Syntax, key Parameter & Examples
August 10, 2026 - The max() function finds the maximum value among elements of an iterable or a series of arguments. It returns the largest item based on the default ordering or a custom ordering specified by the optional key parameter. When used with iterables like lists or tuples, the function compares the ...