Latest web development tutorials

Python3 max() 函數

Python3 數字 Python3數字


描述

max() 方法返回給定參數的最大值,參數可以為序列。


語法

以下是max() 方法的語法:

max( x, y, z, .... )

參數

  • x -- 數值表達式。
  • y -- 數值表達式。
  • z -- 數值表達式。

返回值

返回給定參數的最大值。

實例

以下展示了使用max() 方法的實例:

#!/usr/bin/python3

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

Python3 數字 Python3數字