 # Python Program To Find Smallest Number In The Python List?

In this article, we are going to see how we can find the smallest number present in the list. Let's understand the topic with the help of some sample data.

For Examples:

``````Input: [22, 53, 75, 64, 24]
Output: 22
â€‹
Input: [54, 23, 18, 83, 66]
Output: 18``````

The different ways to find out the smallest element present in the list are:

1. Using sort() method

2. Using min() method

3. Without using built-in functions

## Find the smallest number in the list Using the sort() method in Python

In this approach, we sort the list of numbers in ascending order with the help of the sort() method and then we print the first element present in the list.

### Algorithm

Step 1: Create a list of numbers

Step 2: Use the sort() method to sort the list in ascending order

Step 3: Print the first element of the list

See the below Python code implementation of the above algorithm.

``````# Python program to find the smallest
# number in a list using sort()
â€‹
# list of the numbers
list1 = [54, 23, 18, 83, 66]
â€‹
# sorting the list
list1.sort()
â€‹
# printing the last element
print("The smallest element is:", list1)``````

Output:

The smallest element is: 18

## Find the smallest number in the list Using the min() method in Python

In this method, we will use the built-in function min() which will find out the smallest number present in the given list and return that element.

### Algorithm

Step 1: Create a list of numbers

Step 2: Use min() method to get smallest number

Step 3: Print that smallest number

See the below Python code implementation of the above algorithm.

``````# Python program to find the smallest
# number in a list using min()
â€‹
# list of the numbers
list2 = [54, 23, 18, 83, 66]
â€‹
# printing the smallest element
print("The smallest element is:", min(list2))``````

â€‹Output:

The smallest element is: 18

## Find the smallest number in the list Using for loop in Python

In this approach, we will find out the smallest element present in the list using a for loop.

### Algorithm

Step 1: Define a function that will find the smallest number

Step 2: Declare the variable that will store the smallest number

Step 3: Set the value of the variable to the first element of the list

Step 4: Start a for loop

Step 5: Compare each element with the variable which stores the largest value

Step 6: If the element is smaller than the value in the variable then set that element as the value of the variable

Step 7: Return the result

Step 9: Print the result

See the below Python code implementation of the above algorithm.

``````# Python program to find smallest
# number in a list without using built-in functions
â€‹
def myLar(list1):
â€‹
Â  Â # Assume the first number in the list is smallest
Â  Â # initially and assign it to variable "small"
Â  Â small = list1
â€‹
Â  Â # Now traverse through the list and compare
Â  Â # each number with "small" value. Whichever is
Â  Â # smallest assign that value to "small'.
Â  Â for x in list1:
Â  Â  Â  Â if x < small:
Â  Â  Â  Â  Â  Â small = x
â€‹
Â  Â # after complete traversing the list
Â  Â # return the "small" value
Â  Â return small
â€‹
â€‹
# Driver code
list1 = [54, 23, 18, 83, 66]
print("The smallest element is:", myLar(list1))``````

Output:

The smallest element is: 18

Trending