Minimum And Maximum Of A List Of Numbers In Python

(Last Updated On: 21/11/2022)

Python Program to Print Minimum And Maximum Of A List Of Numbers

# Minimum And Maximum Of A List Of Numbers In Python

m = [4,12,43.5,19,2]

# max used to compute the maximum of the values passed in its argument
print("Maximum number is : ",max(m))

# function is used to compute the minimum of the values passed in its argument
print("Minimum number is : ",min(m))

Output:

Maximum number is :  43.5
Minimum number is :  2

This program brings you very interesting functions of Python, namely max() and min(). 

  • max() – This function is used to compute the maximum of the values passed in its argument and the lexicographically largest value if strings are passed as arguments.
  • min() – This function is used to compute the minimum of the values passed in its argument and the lexicographically smallest value if strings are passed as arguments.

See the magic of predefined functions. If you compare our previous function with this function, you will get to know that we have reduced lines of code. Here we have defined a list with the name m and assigned a value to the list.

In the next line, we have a print statement with a message, and here, we have used the max function and passed the variable m, which returns the max number from the list. Then in the next line, another print statement with the min function will return the minimum number from the list.

Let’s run this program and see if you got the output, Maximum number is 43.5, and the minimum number is 2. I hope now you know how to get the minimum and maximum number with the help of user-defined functions as well as predefined functions.

Leave a Reply

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