w3resource logo


Python Exercises

Python: Write a Python program to get the smallest number from a list


Write a Python program to get the smallest number from a list.

Sample Solution :

Python Code :

  1. def smallest_num_in_list( list ):  
  2.     min = list[ 0 ]  
  3.     for a in list:  
  4.         if a < min:  
  5.             min = a  
  6.     return min  
  7. print(smallest_num_in_list([12, -80]))  

Console :

Copy and paste the above code and press "Enter key" to execute :

Post your code through Disqus