Python Find the Largest Element in a List
Define a list of numbers and find the largest element in the list.
For example:
输入 : list1 = [10, 20, 4] 输出 : 20
Example 1
list1 = [10, 20, 4, 45, 99]
list1.sort()
print("The largest element is:", list1[-1])
list1.sort()
print("The largest element is:", list1[-1])
The output of the above example is:
最大元素为: 99
Example 2: Using the max() Method
list1 = [10, 20, 1, 45, 99]
print("The largest element is:", max(list1))
print("The largest element is:", max(list1))
The output of the above example is:
最大元素为: 99Other Extensions
Python3 Examples