In this article, we will learn to find the smallest number in a list using the python program.
We find the smallest number in a list using 3 different methods:
- Using min() function
- By comparing each element
- By using sort() function
Using min() function
- First, we declared the list.
- Then, we use the min() function to find the smallest number in a list.
- Then we print the small value.
By comparing each element
- First, we declared the list and a small variable.
- And, we assume the first elements as a small number and assign them to the small variable.
- Then we run the for loop and check each element of the loop is smaller than small or not.
- If any element is smaller than the small variable then we update the value of the small variable.
- Then, lastly, we prin the small variable as the smallest number.
Using sort() function
- First, we declare the list.
- And then we use the sort() function to arrange the list in ascending order.
- And then we know that in ascending order the first elements are always smaller.
- So, we print the first element.