Finding the Minimum or Maximum Number in a List using python programing

11/29/2023
All Articles

#Finding the Minimum or Maximum Number in a List using python programing

Finding the Minimum or Maximum Number in a List using python programing

Finding the Minimum or Maximum Number in a List using python programing

List is data structure in python and we need to find minimum or maximum number in a list.
There is many way to find .

  • Python using the built-in function.
  • Using loop you can find min and max value.


 

numberList = [15, 85, 35, 89, 125, 2]

minNum = numberList[0]
for num in numberList:
    if minNum > num:
        minNum = num
print(minNum)

 

 

Below is example to find Maximum value from list :
 

numberList = [19, 85, 38, 88, 135, 2]

minNum = numberList[0]
for num in numberList:
    if minNum < num:
        minNum = num
print(minNum)

 

 

Conclusion :

In this Article we learn to find min and max value of element in list.
you only iterate through the list once instead of twice if you were to use separate min() and max() call.
This example is also important in interview of python.I hope you like this content kindly refer other Article for good understanding.

Article