{"id":25736,"date":"2021-12-04T09:19:57","date_gmt":"2021-12-04T03:49:57","guid":{"rendered":"https:\/\/python-programs.com\/?p=25736"},"modified":"2021-12-04T09:19:57","modified_gmt":"2021-12-04T03:49:57","slug":"python-program-to-find-the-smallest-number-in-3-easy-methods","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-the-smallest-number-in-3-easy-methods\/","title":{"rendered":"Python Program to Find the Smallest Number in 3 Easy Methods"},"content":{"rendered":"

Given a list and the task is to find the smallest number in the given list.<\/p>\n

Let us see this python code in 3 easy methods. They are<\/p>\n

    \n
  1. Using the min() function in Python.<\/li>\n
  2. Using sort() function in Python.<\/li>\n
  3. Using the for loop.<\/li>\n<\/ol>\n

    min() function:<\/strong><\/p>\n

    min() is a Python built-in function that takes a list as an argument and returns the number with the smallest value in the list.<\/p>\n

    sort() Function:<\/strong><\/p>\n

    sort() is another Python built-in method that does not return the smallest number in the list. Instead, it arranges the items in ascending order.
    \nSo, by sorting the list, we can use indexing to access the first element of the list, which will be the smallest number in the list.<\/p>\n

    Examples:<\/strong><\/p>\n

    Example1:<\/strong><\/p>\n

    Input:<\/strong><\/p>\n

    Given list = [9, 6, -3, -20, 4]<\/pre>\n

    Output:<\/strong><\/p>\n

    The given list's [9, 6, -3, -20, 4] smallest value =  -20<\/pre>\n

    Example2:<\/strong><\/p>\n

    Input:<\/strong><\/p>\n

    Given list =  [3, 7, 8, 1, 0]<\/pre>\n

    Output:<\/strong><\/p>\n

    The given list's [3, 7, 8, 1, 0] smallest value = 0<\/pre>\n

    Program to Find the Smallest Number in 3 Easy Methods<\/h2>\n