How to Find Maximum and Minimum Values?

How to Find Maximum and Minimum Values?

 
This is mostly used to find max and min values. If the data is large so it too difficult to identify the max and min values. In Python, there is a function called max() and min(). Where max is used to find maximum value and min used to find the minimum value.

Syntax to find max and min

max()

min()

How do you find the max and min in Python? Examples

We can find maximum value and minimum value from the list in different ways in python.

1st way to find max and min values:

num1=[163,45,28,85,214,101]
print("Minimum value is:",min(num1))
print("Maximum value is:",max(num1))

Output:

C:\Users\Pramod\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Pramod/PycharmProjects/pythonProject/main.py
Minimum value is: 28
Maximum value is: 214

Process finished with exit code 0

2nd way to find max and min values:

def max_Min_diff(num):
return max(num) - min(num)
num1=[163,45,28,85,214,101]
print("The difference of max and min is:",max_Min_diff(num1))

Output:

C:\Users\Pramod\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Pramod/PycharmProjects/pythonProject/main.py
The difference of max and min is: 186

Process finished with exit code 0

3rd way Max and Min using def

def max_min(num):
return "maximum:->",max(num),"minimum:-> ",min(num)
num1=[163,45,28,85,214,101]
print(max_min(num1))

Output:

C:\Users\Pramod\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Pramod/PycharmProjects/pythonProject/main.py
('maximum:->', 214, 'minimum:-> ', 28)

Process finished with exit code 0

Recommended Post:

Get Salesforce Answers

Pramod Kumar Yadav is from Janakpur Dham, Nepal. He was born on December 23, 1994, and has one elder brother and two elder sisters. He completed his education at various schools and colleges in Nepal and completed a degree in Computer Science Engineering from MITS in Andhra Pradesh, India. Pramod has worked as the owner of RC Educational Foundation Pvt Ltd, a teacher, and an Educational Consultant, and is currently working as an Engineer and Digital Marketer.



Leave a Comment