Menu Close

Python Program to Find Smallest Number in a List

Smallest number in a list

In this tutorial, we will see various examples to find the smallest number in list. Here we will use the python min() and sort() function as well as for loop to write a python program to find the smallest number in a list.

At the end of this article, you will able to find the smallest number in a list of python using different-different ways.

Python program to find smallest number in a list

In this example we will use python built-in min() function.


#list of numbers
list1 = [-12, 23, -46, -35, 22, 13, 67]
print('List is:- ', list1)

#find smallest number from list using min() function
print('Smallest Number in list:- ', min(list1))

Output will be:- -46

Smallest number in list python using sort() function

In this example we will use python built-in sort() function.


#list of numbers
list1 = [-12, 23, -50, -35, 22, 13, 67]
print('List is:- ', list1)
#convert list item in ascending order using sort() function
list1.sort()

print('Sorted list is:- ', list1[0])

Output will be:- -50

Smallest number in list python using for loop

In this example, we will ask for multiple values from the user and store them in the list and then find the smallest value from them using for loop.


num = int(input('Enter how many element you want in list:- '))
list1 = []

for i in range(1, num + 1):
    element = input(f'Enter {i} element:- ')
    list1.append(int(element))

print('List is:- ', list1)  
print('Smallest Number in list:- ', min(list1)) 

Click Here to learn for loop.

Output


Enter how many element you want in list:- 4
Enter 1 element:- 12
Enter 2 element:- 10
Enter 3 element:- 5
Enter 4 element:- 50

List is:-  [12, 10, 5, 50]
Smallest Number in list:-  5

Conclusion

Here we have seen how to write a python program to find the smallest number in a list as well as we have seen three different ways to find the smallest number from the list.
If you are a beginner python programmer, Then this example is very helpful for you. If you like this article, please share it with others who want to learn Python programming.

For more information:- Click here

Python programs


Python Program to Swap Two Numbers
Reverse a String in Python ( 5 best ways )

Related Posts