Largest Element in List in Python
Find the largest element in a list of numbers.
BeginnerList ProgramsExample 2 of 25
largest-element-in-list.py
Run in browser1# Program to find largest element in a list23numbers = list(map(float, input("Enter numbers separated by space: ").split()))45if not numbers:6 print("List is empty.")7else:8 print("Largest element:", max(numbers))
Output
Enter numbers separated by space: 3 7 2 9 Largest element: 9.0
What's going on
We use the built-in max() to obtain the largest value, with an empty-list check.