pal4life
0
Q:

max in python

import sys
MAX_INT = sys.maxsize - 1
0
li=[0,70,7,89]
max(li)
#gives the max value 89
2
# find largest item in the string
print(max("abcDEF")) 

# find largest item in the list
print(max([2, 1, 4, 3])) 

# find largest item in the tuple
print(max(("one", "two", "three"))) 
'two'

# find largest item in the dict
print(max({1: "one", 2: "two", 3: "three"})) 
3

# empty iterable causes ValueError
# print(max([])) 

# supressing the error with default value
print(max([], default=0)) 
1
i = max(2, 4, 6, 3)

print(i)
# Result will be 6 because it is the highest number
3
print(max(2, 3)) # Returns 3 as 3 is the largest of the two values
print(max(2, 3, 23)) # Returns 23 as 23 is the largest of all the values

list1 = [1, 2, 4, 5, 54]
print(max(list1)) # Returns 54 as 54 is the largest value in the list
0
# use a list, tupal or dictonary to find the max value
a = (1, 5, 3, 9)
x = max(a) 
0
max([2, 1, 4, 3])
0
#!/usr/bin/python

list1, list2 = [123, 'xyz', 'zara', 'abc'], [456, 700, 200]
print "Max value element : ", max(list1)
print "Max value element : ", max(list2)
-1

New to Communities?

Join the community