查找列表中最大数字的 Python 程序


在本文中,我们将学习解决给定问题陈述的解决方案和方法。

题目陈述

给定列表输入,我们需要找到给定列表中的最大数字。

在此处,我们将讨论两种方法

  • 使用排序技术
  • 使用内置 max() 函数

方法 1 - 使用内置 sort() 函数

示例

 在线演示

list1 = [18, 65, 78, 89, 90]
list1.sort()
# main
print("Largest element is:", list1[-1])

输出

Largest element is: 90

Learn Python in-depth with real-world projects through our Python certification course. Enroll and become a certified expert to boost your career.

方法 2 - 使用内置 max() 函数

示例

 在线演示

list1 = [18, 65, 78, 89, 90]
# main
print("Largest element is:",max(list1))

输出

Largest element is: 90

结论

在本文中,我们学习了找到列表中最大数字的方法。

更新于:04-07-2020

257 次浏览

开启您的 职业

完成课程认证

开始学习
广告