1import sys
2MAX_INT = sys.maxsize
3print(MAX_INT)
4
5''' NOTE: value of sys.maxsize is depend on the fact that how much bit a machine is. '''
1i = max(2, 4, 6, 3)
2
3print(i)
4# Result will be 6 because it is the highest number
1The max() function returns the largest of the input values.
2
3Syntax:
4 max(iterable, *[, key, default])
5 max(arg1, arg2, *args[, key])
6
7 PARAMETER DESCRIPTION
8 iterable | An iterable object like string, list, tuple etc.
9 (required)
10 default | The default value to return if the iterable is empty.
11 (optional)
12 key | It refers to the single argument function to customize the sort
13 (optional) order. The function is applied to each item on the iterable.
14
15
16Example:
17 max([2, 1, 4, 3]) # Output: 4
18 max([], default=0) # supressing the error with default value, Output: 0
19 max("c", "b", "a", "Y", "Z") # Output: c
20 max("c", "b", "a", "Y", "Z", key=str.lower) # Output: Z
21
1print(max(2, 3)) # Returns 3 as 3 is the largest of the two values
2print(max(2, 3, 23)) # Returns 23 as 23 is the largest of all the values
3
4list1 = [1, 2, 4, 5, 54]
5print(max(list1)) # Returns 54 as 54 is the largest value in the list