How to find Maximum Value in a List in Python

Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about to find Maximum Value in a List in Python. In your list we can find out the maximum value also we can also find out the index of the maximum value. So here we are going to learn about that. So here i am giving you some methods to find out the maximum value also giving some method which will be helpful to find out the index of the max value. So without wasting your time lets learn this by given methods:

How to find Maximum Value in a List in Python

  1. Find Maximum Value in a List in Python

    to find Maximum Value in a List in Python just Use for loop. By using loop you can find out the maximum value of the list. Here i am making a list and put it in for loop. By using for loop you can find out the maximum value of the list. So lets learn this by given example. It is very simple and easy method. Lets learn this. mylist = [52,84,95,65,45,10,54] maxvalue = None for num in mylist: if (maxvalue is None or num > maxvalue): maxvalue = num print('Maximum value:', maxvalue) Output : Maximum value: 95 You can also find out the index of the max value by using the for loop. So here i am giving the example where you can find the both value, the max value and the index of the max. mylist = [52,84,95,65,45,10,54] maxvalue = None idxOFmax = None for idx, num in enumerate(mylist): if (maxvalue is None or num > maxvalue): maxvalue = num idxOFmax = idx print('Maximum value:', maxvalue, "At index: ", idxOFmax)
    Output : Maximum value: 95 At index: 2

  2. How to find Maximum Value in a List in Python

    to find Maximum Value in a List in Python just Use max().max() function also use to find out the max value of a list in python. first make your list and then put the list in max() function and print it. I hope you guys like this method : mylist = [52,84,95,65,45,10,54] maxvalue = max(mylist) print('Maximum value:', maxvalue) Output : Maximum value: 95

Method 1: Use for loop

By using loop you can find out the maximum value of the list. Here i am making a list and put it in for loop. By using for loop you can find out the maximum value of the list. So lets learn this by given example. It is very simple and easy method. Lets learn this.

mylist = [52,84,95,65,45,10,54]
maxvalue = None
for num in mylist:
    if (maxvalue is None or num > maxvalue):
        maxvalue = num
print('Maximum value:', maxvalue)

Output :

Maximum value: 95

You can also find out the index of the max value by using the for loop. So here i am giving the example where you can find the both value, the max value and the index of the max.

mylist = [52,84,95,65,45,10,54]
maxvalue = None
idxOFmax = None
for idx, num in enumerate(mylist):
    if (maxvalue is None or num > maxvalue):
        maxvalue = num
        idxOFmax = idx
print('Maximum value:', maxvalue, "At index: ", idxOFmax)

Output :

Maximum value: 95 At index:  2

Method 2: Use max()

max() function also use to find out the max value of a list in python. first make your list and then put the list in max() function and print it. I hope you guys like this method :

mylist = [52,84,95,65,45,10,54]
maxvalue = max(mylist)
print('Maximum value:', maxvalue)

Output :

Maximum value: 95

Method 3: max() for the list of strings

If you find out the max string than this method will be helpful for you guys. Here A alphabet consider as the smallest and Z as the largest value. Lets see this by given example:

mystr = ['zibra', 'kite', 'bat', 'Joker', 'dog', 'Cat']
maxvalue = max(mystr)
print('Maximum value:', maxvalue, "At index:", mystr.index(maxvalue))

Output :

Maximum value: zibra At index: 0

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment