Python Get Maximum Value Function

Document 对象参考手册Python3 Examples

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

Example (Python 3.0+)

# -*- coding: UTF-8 -*- # Filename : test.py # author by : www.example.com # Simplest print(max(1, 2)) print(max('a', 'b')) # Can also be used on lists and tuples print(max([1,2])) print(max((1,2))) # More examples print("The maximum value of 80, 100, 1000 is:", max(80, 100, 1000)) print("The maximum value of -20, 100, 400 is:", max(-20, 100, 400)) print("The maximum value of -80, -20, -10 is:", max(-80, -20, -10)) print("The maximum value of 0, 100, -400 is:", max(0, 100, -400))

Executing the above code produces the following output:

2
b
2
2
80, 100, 1000 最大值为:  1000
-20, 100, 400最大值为:  400
-80, -20, -10最大值为:  -10
0, 100, -400最大值为: 100

Introduction to the max() function:Python max()Function.

Document 对象参考手册Python3 Examples

Other Extensions