Python max() built-in function

From the Python 3 documentation

Return the largest item in an iterable or the largest of two or more arguments.

Introduction

The max() function can be used in two ways:

  1. With an iterable (like a list or tuple), it returns the largest item.
  2. With two or more arguments, it returns the largest of them.

Examples

Finding the max in an iterable:

numbers = [1, 2, 10, 40, 5]
print(max(numbers))  # Output: 40

letters = ('a', 'b', 'z')
print(max(letters)) # Output: 'z'

Finding the max of several arguments:

print(max(10, 20, 5)) # Output: 20

Subscribe to pythoncheatsheet.org

Join 16,702+ Python developers in a two times a month and bullshit free publication , full of interesting, relevant links.