How to get max and min value of an array in python.
Estimated Reading Time: 2 minutes
How to get the max and min values of an array in Python
In Python, you can create an array, full of functions to perform with. In this article, it will explain to you how to get the minimum and the maximum value of an array. This tip can be used for other data types, so make sure to read the whole page until the end.
How to get the minimum value
To get the minimum value of an array, you can use the min()
function. The min() function will return the minimum value of a data set(including variables and arrays) given inside the brackets ().
scores = [0,100,200,300]
print(min(scores)) #returns 0, the smallest in the array "scores"
# = 0
How to get the maximum value
In Python, you can create an array, full of functions to perform with. In this article, it will explain to you how to get the minimum and the maximum value of an array. This tip can be used for other data types, so make sure to read the whole page until the end.
How to get the minimum value
To get the maximum value of an array, you can use the max()
function. Just like the min() function, the min() function will return the maximum value of a data set(including variables and arrays) given inside the brackets ().
wins = [20,28,39,68]
print(max(wins)) #returns 68, the largest in the array "wins"
# = 0
Conclusion
Overall, it is pretty easy to get both the minimum and the maximum value of an array in Python. Yet, knowing this function makes a huge difference from the others that don’t know.
If this article was helpful, please consider sharing the link to your SNS.
Thank you for reading.