Python max() 函數
描述
max() 方法返回給定參數的最大值,參數可以為序列。
語法
以下是 max() 方法的語法:
max( x, y, z, .... )
參數
- x -- 數值運算式。
- y -- 數值運算式。
- z -- 數值運算式。
返回值
返回給定參數的最大值。實例
以下展示了使用 max() 方法的實例:
實例(Python 2.0+)
#!/usr/bin/python
print "max(80, 100, 1000) : ", max(80, 100, 1000)
print "max(-20, 100, 400) : ", max(-20, 100, 400)
print "max(-80, -20, -10) : ", max(-80, -20, -10)
print "max(0, 100, -400) : ", max(0, 100, -400)
以上實例運行後輸出結果為:
max(80, 100, 1000) : 1000 max(-20, 100, 400) : 400 max(-80, -20, -10) : -10 max(0, 100, -400) : 100