min(S)函数

min(S)函数

描述

Python min()函数返回字符串中最小的字母。

语法

min()函数语法:

min(str)

参数

  • str -- 字符串。

返回值

返回字符串中最小的字母。

实例

以下实例展示了min()函数的使用方法:

str = "runoob"
print("最小字符:", min(str))  # b

有大写字母的时候,返回时小的大写字符。

str = "runoobBo"
print("最小字符:", min(str))  # B

max(str)、min(str) 方法不只判断字母,会判断字符串中的所有字符,按照字符在 unicode 中的编码值来决定大小:

str = "12345"
print(max(str))  # 5
print(min(str))  # 1

str = "a呵呵/"
print(max(str))  #
print(min(str))  # /
原文地址:https://www.cnblogs.com/xiaohei001/p/10161531.html