Python 3 教程教程
Python 查找列表中最大元素
Python 查找列表中最大元素
Python 查找列表中最大元素
Python3 实例定义一个数字列表,并查找列表中的最大元素。
例如:
输入 : list1 = [10, 20, 4] 输出 : 20
实例 1
list1 = [10, 20, 4, 45, 99]
list1.sort()
print("最大元素为:", list1[-1])
list1.sort()
print("最大元素为:", list1[-1])
以上实例输出结果为:
最大元素为: 99
实例 2:使用 max() 方法
list1 = [10, 20, 1, 45, 99]
print("最大元素为:", max(list1))
print("最大元素为:", max(list1))
以上实例输出结果为:
最大元素为: 99Python3 实例
Python 查找列表中最大元素 |
---|
Python 3 教程
Python的3.0版本,常被称为Python 3000,或简称Py3k。相对于Python的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0在设计的时候没有考虑向下兼容。