max python 3 code example
Example 1: get biggest value in array python3
array = [1,2,3,100,4,5]
biggest = max(array)
print(biggest) # prints 100
Example 2: max value in python
# 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))
Example 3: python max()
i = max(2, 4, 6, 3)
print(i)
# Result will be 6 because it is the highest number
Example 4: max func in python
max([2, 1, 4, 3])
#Returns 4 as it's the largest integer in the list
Example 5: max function python
max([2, 1, 4, 3])