Python字串max()方法

Python字串max()方法從字串str返回最大字母字元。

語法

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

max(str)

參數

  • str - 這是需要從中返回最大字母字元的字串。

返回值

  • 此方法從給定字串str中返回最大字母字元。

示例

以下示例顯示了max()方法的用法 -

#!/usr/bin/python3

str = "this is a string example....really!!!"
print ("Max character: " + max(str))

str = "this is a string example....wow!!!"
print ("Max character: " + max(str))

當運行上面的程式,它產生以下結果 -

Max character: y
Max character: x

上一篇: Python字串 下一篇: Python列表