Python List max() Method (original) (raw)
Last Updated : 17 Apr, 2025
**max() function in Python is a built-in function that finds and returns the largest element from the list. Let’s understand it better with an example:
Python `
a = [2,3,6,1,8,4,9,0] print(max(a))
`
Syntax
max(listname)
**Parameter:
- **listname : Name of list in which we have to find the maximum value.
**Return Type: It return the maximum value present in the list.
Python List max() Method Example
Lets look at some examples to find max element in Python list:
Example 1: Finding Maximum in a List of Integers
In this example, we will find the maximum value from a list containing integers using Python’s max() method.
Python `
a = [4, -4, 8, -9, 1] res = max(a)
print(res)
`
**Explanation: The max() function is used to find the largest value in the list **a. It compares all elements and returns the highest value. The result is stored in the variable **res, which is then printed.
Example 2: Finding Maximum in a List of Characters
In this example, we are going to find the maximum value from the list of characters. This is done by following same procedure as in example 1.
Python `
a = ['a', '$', 'e', 'E'] res = max(a) print(res)
`
**Explanation: In this case of character values the max value is determined on the basis of their ASCII values. For example ASCII value of ‘e’ is 101 and ‘E’ is 69 therefore ‘e’ is larger.
Example 3: Finding Maximum in a List with Mixed Data Types
In this example, we are going to try to find the maximum value from the list of mixed values such as integers and strings.
Python `
a = ['!', '$', '/', '3', '61'] res = max(a) print(res)
`
**Explanation: In the ASCII table, digits ‘0’ to ‘9’ have values from 48 to 57. Since all elements in the list are strings, max() compares them based on the first character’s ASCII value. For example, ’61’ starts with ‘6’, which has a higher value than ‘3’ or ‘1’. If the list had ’16’ instead of ’61’, then ‘3’ would be the maximum, because ‘1’ (from ’16’) has a lower ASCII value than ‘3’.
**Related Articles: