BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Python Program to Find Smallest Number in a List

By Chaitanya Singh | Filed Under: Python Examples

In this tutorial, we will see various Python programs to find the smallest number in a List. For example, if the list is [15, 20, 10, 16] then the program should display number 10 as the output (the smallest number in the given list).

Example 1: Finding smallest number in a list using sort() method

In the following program, we are finding the smallest number in the given list using sort() function. The sort() function sorts the given list in ascending order. We are then displaying the first element of the list, which is the smallest number of the sorted list.

# Python program to find smallest number in a list

# Given list of numbers
lis = [89, 100, 35, 16, 99]

# sorting the given list "lis"
# sort() function sorts the list in ascending order
lis.sort()

# Displaying the first element of the list
# which is the smallest number in the sorted list
print("Smallest number in the list is:", lis[0])

Output:
Python Program to Find Smallest Number in a List

Example 2: Finding smallest number in a list using min() method

In the following program we are finding the smallest number of the list using min() method. The min() method returns the smallest element of the list.

# Python program to find smallest number in the
# given list using min() method

# Given list of numbers
lis = [9, 100, 3, 16, 60]

# min() method returns the smallest element of the list
print("Smallest number of the list is:", min(lis))

Output:
Finding smallest number in a list using min() method

Example 3: Finding smallest number in a list, where list is provided by user

In the following program we are finding the smallest number in the user provided list, user is asked to enter the number of elements to put in a list. User then enters the elements of the list one by one, each input element is appended to the list using append() method. At the end of the program, the smallest number of the list is displayed using min() method.

# creating empty list
lis = []

# user enters the number of elements to put in list
count = int(input('How many numbers? '))

# iterating till count to append all input elements in list
for n in range(count):
    number = int(input('Enter number: '))
    lis.append(number)

# displaying smallest element
print("Smallest element of the list is :", min(lis))

Output:
Smallest Number in user provided list

Related Python Examples

  1. Python program to find largest number in a list
  2. Python program to find largest among three numbers
  3. Python program to convert decimal to hexadecimal
  4. Python program to swap two numbers

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Python Tutorial

Introduction

  • Python Tutorial
  • Python Introduction
  • Install Python
  • PyCharm IDE Installation
  • Python in PyCharm
  • Python Comments
  • Python Variables
  • Python Keywords & Identifiers
  • Python data types

Flow Control

  • Python If
  • Python if..else
  • Python if..elif..else
  • Python Nested If
  • Python for loop
  • Python while loop
  • Python break
  • Python continue
  • Python pass

Python Functions

  • Python Functions
  • Python Recursion

Python Datatypes

  • Python Numbers
  • Python List
  • Python Strings
  • Python Tuple
  • Python Dictionary
  • Python Set

Python OOPs

  • Python OOP
  • Python Class & Object
  • Python Constructors

Python Examples

  • Python Programs

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap