Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

What is max() in Python?

Mahnoor Zaheer

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The max() method in Python returns the largest value from an iterable object.

Syntax

This method is declared as follows:

The syntax of max() method in Python

Parameter and return value

The max() method takes one mandatory parameter that is an iterable object. This iterable object can be a list or a tuple of integers, floating point numbers, strings or characters.

The return value of this function is the greatest value among other values, depending on the argument type.

For instance, in a list of integers, max() returns the largest integer; in a list of strings, it returns the string which has the maximum rank, alphabetically.

Example

In the example below, the max() method returns the largest value from the list of integers, floating point numbers, and strings.

# List of integers
int_list = [2, 7, 3, 9]
print(max(int_list))
# List of floating point numbers
float_list = [12.1, 7.2, 3.5, 9.9]
print(max(float_list))
# List of strings
str_list = ["xyz", "abcf", "abd", "ghij"]
print(max(str_list))

RELATED TAGS

python
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring