Smallest Element in List in Python
Find the smallest element in a list of numbers.
BeginnerList ProgramsExample 3 of 25
smallest-element-in-list.py
1# Program to find smallest 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("Smallest element:", min(numbers))
Output
Enter numbers separated by space: 3 7 2 9 Smallest element: 2.0
What's going on
We use the built-in min() to obtain the smallest value, again checking for an empty list.
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.