🌐
W3Schools
w3schools.com › python › ref_func_max.asp
Python max() Function
Python Examples Python Compiler ... Certificate Python Training ... The max() function returns the item with the highest value, or the item with the highest value in an iterable....
🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.3 documentation
February 27, 2026 - Binary files are buffered in fixed-size chunks; the size of the buffer is max(min(blocksize, 8 MiB), DEFAULT_BUFFER_SIZE) when the device block size is available.
People also ask

What is the use of the max() and min() functions in Python?
We use Python's max() and min() functions to get the maximum or minimum object out of a set of objects or max/min object out of objects in a given iterable.
🌐
interviewkickstart.com
interviewkickstart.com › home › blogs › learn › max() function in python: syntax, parameters, and examples
max() Function in Python: Syntax, Parameters & Examples
What is the difference between the Python max() and min() functions?
Both compare items or items within an iterable on some basis and return a value. But the max() function in Python returns the max value after those comparisons, and the min() function returns the minimum value.
🌐
interviewkickstart.com
interviewkickstart.com › home › blogs › learn › max() function in python: syntax, parameters, and examples
max() Function in Python: Syntax, Parameters & Examples
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-max-function
Python - max() function - GeeksforGeeks
July 15, 2025 - Python max() function returns the largest item in an iterable or the largest of two or more arguments.
🌐
Programiz
programiz.com › python-programming › methods › built-in › max
Python max()
max() returns the largest element from an iterable. ... If the items in an iterable are strings, the largest item (ordered alphabetically) is returned. languages = ["Python", "C Programming", "Java", "JavaScript"]
🌐
Real Python
realpython.com › ref › builtin-functions › max
max() | Python’s Built-in Functions – Real Python
The built-in max() function allows you to find the largest values in an iterable or among multiple arguments.
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › max.html
max — Python Reference (The Right Way) 0.1 documentation
Returns the largest item in an iterable or the largest of two or more arguments · max (collection[, key])
🌐
Tutorialspoint
tutorialspoint.com › python › list_max.htm
Python List max() Method
The Python List max() method compares the elements of the list and returns the maximum valued element. If the elements in the list are numbers, the comparison is done numerically; but if the list contains strings, the comparison is done
🌐
Tutorialspoint
tutorialspoint.com › python › number_max.htm
Python max() Function
The Python max() function is used to retrieve the largest element from the specified iterable. Finding the maximum of two given numbers is one of the usual calculations we perform.
Find elsewhere
🌐
Interview Kickstart
interviewkickstart.com › home › blogs › learn › max() function in python: syntax, parameters, and examples
max() Function in Python: Syntax, Parameters & Examples
December 23, 2024 - The max() function returns the largest item in a sequence or group of values, while min() returns the smallest. In practice, both follow the same pattern, but they answer opposite questions, so the choice depends on whether you want the highest ...
🌐
Vultr Docs
docs.vultr.com › python › built-in › max
Python max() - Find Maximum Value | Vultr Docs
September 27, 2024 - The max() function in Python is a built-in utility that identifies the maximum value among the provided arguments or elements within an iterable.
🌐
Unstop
unstop.com › home › blog › python max() function | all use cases with code examples
Python max() Function | All Use Cases With Code Examples
February 12, 2025 - Python max() function helps find the largest value among multiple objects or iterable items. Use the optional parameters key & default to customize its behavior.
🌐
Hyperskill
hyperskill.org › university › python › max-in-python
Python max()
December 25, 2025 - This course is dedicated to core Python skills that will give you a solid base and allow you to pursue any further direction, be it Backend Development or Data Science. ... The max() function in Python is commonly employed to identify the value from a provided collection of elements.
🌐
Real Python
realpython.com › python-min-and-max
Python's min() and max(): Find Smallest and Largest Values – Real Python
January 18, 2025 - Python’s built-in functions max() and min() allow you to find the largest and smallest values in a dataset. You can use them with iterables, such as lists or tuples, or a series of regular arguments.
🌐
HowToDoInJava
howtodoinjava.com › home › python examples › python max() and min(): find max and min in array
Python max() and min(): Find max and min in Array
September 21, 2023 - Python provides two handy functions, max() and min(), that makes it easy to find the largest (or the smallest) item in any iterable (e.g.
Top answer
1 of 8
417

lambda is an anonymous function, it is equivalent to:

def func(p):
   return p.totalScore     

Now max becomes:

max(players, key=func)

But as def statements are compound statements they can't be used where an expression is required, that's why sometimes lambda's are used.

Note that lambda is equivalent to what you'd put in a return statement of a def. Thus, you can't use statements inside a lambda, only expressions are allowed.


What does max do?

max(a, b, c, ...[, key=func]) -> value

With a single iterable argument, return its largest item. With two or more arguments, return the largest argument.

So, it simply returns the object that is the largest.


How does key work?

By default in Python 2 key compares items based on a set of rules based on the type of the objects (for example a string is always greater than an integer).

To modify the object before comparison, or to compare based on a particular attribute/index, you've to use the key argument.

Example 1:

A simple example, suppose you have a list of numbers in string form, but you want to compare those items by their integer value.

>>> lis = ['1', '100', '111', '2']

Here max compares the items using their original values (strings are compared lexicographically so you'd get '2' as output) :

>>> max(lis)
'2'

To compare the items by their integer value use key with a simple lambda:

>>> max(lis, key=lambda x:int(x))  # compare `int` version of each item
'111'

Example 2: Applying max to a list of tuples.

>>> lis = [(1,'a'), (3,'c'), (4,'e'), (-1,'z')]

By default max will compare the items by the first index. If the first index is the same then it'll compare the second index. As in my example, all items have a unique first index, so you'd get this as the answer:

>>> max(lis)
(4, 'e')

But, what if you wanted to compare each item by the value at index 1? Simple: use lambda:

>>> max(lis, key = lambda x: x[1])
(-1, 'z')

Comparing items in an iterable that contains objects of different type:

List with mixed items:

lis = ['1','100','111','2', 2, 2.57]

In Python 2 it is possible to compare items of two different types:

>>> max(lis)  # works in Python 2
'2'
>>> max(lis, key=lambda x: int(x))  # compare integer version of each item
'111'

But in Python 3 you can't do that any more:

>>> lis = ['1', '100', '111', '2', 2, 2.57]
>>> max(lis)
Traceback (most recent call last):
  File "<ipython-input-2-0ce0a02693e4>", line 1, in <module>
    max(lis)
TypeError: unorderable types: int() > str()

But this works, as we are comparing integer version of each object:

>>> max(lis, key=lambda x: int(x))  # or simply `max(lis, key=int)`
'111'
2 of 8
25

Strongly simplified version of max:

def max(items, key=lambda x: x):
    current = item[0]
    for item in items:
        if key(item) > key(current):
            current = item
    return current

Regarding lambda:

>>> ident = lambda x: x
>>> ident(3)
3
>>> ident(5)
5

>>> times_two = lambda x: 2*x
>>> times_two(2)
4
🌐
Flexiple
flexiple.com › python › python-max-function
Python Max function - All you need to know - Flexiple Tutorials - Flexiple
As the name suggests the Max function in Python is used to return the largest (Maximum) element. Although the value returned is always the largest the methods it uses to arrive at it is based on the arguments passed as a parameter.
🌐
Career Karma
careerkarma.com › blog › python › python min and max: the ultimate guide
Python Min and Max: The Ultimate Guide | Career Karma
December 1, 2023 - The max() method then calculated which of these names comes last alphabetically and returned that name to the program. Finally, our code printed out a message that stated the name that appears last in the alphabet. Often, when you’re working with lists or strings, you’ll want to find the lowest or highest value that appears in that list or string. The Python min() and max() methods can be used to do so.