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
Run in browser
1# Program to find smallest element in a list
2
3numbers = list(map(float, input("Enter numbers separated by space: ").split()))
4
5if 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.