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 :

def smallest_num_in_list( list ):
    min = list[ 0 ]
    for a in list:
        if a < min:
            min = a
    return min
print(smallest_num_in_list([1, 2, -8, 0]))

Console :

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

Post your code through Disqus