Latest web development tutorials

Python get maximum function

Document Object Reference Examples Python3

The following examples we use max () method of selecting the maximum value:

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

# Filename : test.py
# author by : www.w3big.com

# 最简单的
print(max(1, 2))
print(max('a', 'b'))
 
# 也可以对列表和元组使用
print(max([1,2]))
print(max((1,2)))

# 更多实例
print("80, 100, 1000 最大值为: ", max(80, 100, 1000))
print("-20, 100, 400最大值为: ", max(-20, 100, 400))
print("-80, -20, -10最大值为: ", max(-80, -20, -10))
print("0, 100, -400最大值为:", max(0, 100, -400))

Execute the above code output results:

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

max () function description: the Python max () function.

Document Object Reference Examples Python3