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:
- Python Hello World Program
- Python Comment | Creating a Comment | multiline comment | example
- Python Dictionary Introduction | Why to use dictionary | with example
- How to do Sum or Addition in python
- Python Reverse number
- find the common number in python
- addition of number using for loop and providing user input data in python
- Python Count char in String
- Python Last Character from String
- Python Odd and Even | if the condition
- Python Greater or equal number
- Python PALINDROME NUMBER
- Python FIBONACCI SERIES
- Python Dictionary | Items method | Definition and usage
- Python Dictionary | Add data, POP, pop item, update method
- Python Dictionary | update() method
- Delete statement, Looping in the list In Python
- Odd and Even using Append in python
- Python | Simple Odd and Even number
Get Salesforce Answers