Easy Tutorial
❮ Ref Math Gamma Python Swap Variables ❯

Python Get Maximum Value Function

Python3 Examples

In the following examples, we use the max() method to find the maximum value:

Example (Python 3.0+)

# -*- coding: UTF-8 -*-

# Filename : test.py
# author by : www.tutorialpro.org

# Simplest example
print(max(1, 2))
print(max('a', 'b'))

# Can also be used with lists and tuples
print(max([1, 2]))
print(max((1, 2)))

# More examples
print("The maximum value among 80, 100, 1000 is: ", max(80, 100, 1000))
print("The maximum value among -20, 100, 400 is: ", max(-20, 100, 400))
print("The maximum value among -80, -20, -10 is: ", max(-80, -20, -10))
print("The maximum value among 0, 100, -400 is: ", max(0, 100, -400))

Executing the above code will output the following results:

2
b
2
2
The maximum value among 80, 100, 1000 is:  1000
The maximum value among -20, 100, 400 is:  400
The maximum value among -80, -20, -10 is:  -10
The maximum value among 0, 100, -400 is: 100

For more details on the max() function, see the Python max() function.

Python3 Examples

❮ Ref Math Gamma Python Swap Variables ❯