python max number code example
Example 1: max int value in python
import sys
MAX_INT = sys.maxsize
print(MAX_INT)
''' NOTE: value of sys.maxsize is depend on the fact that how much bit a machine is. '''
Example 2: min int python
import sys
MIN_INT = -sys.maxsize - 1
Example 3: python largest value in list
>>> list = [1, 3, 2, 0]
>>> max(list)
3
Example 4: 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 5: python max()
i = max(2, 4, 6, 3)
print(i)
# Result will be 6 because it is the highest number
Example 6: max function python
max([2, 1, 4, 3])