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
1# 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.
After this program
If the idea is still fuzzy, read Day 5: Lists and List Methods in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 25 list programs, or see every topic on Python exercises.