max(arg1,arg2, key=my_fun )
arg1, arg2 :numbers , iterable inputs or more than one inputs x=4
y=7
print(max(x,y)) # 7
Using list
my_list=[1,2,3,4,5]
print(max(my_list)) # 5
my_list=['Hello','Welcome','To','Plus2net']
print(max(my_list)) # Welcome
my_list=['Hello','Welcome','to','plus2net']
print(max(my_list)) # to
Using Dictionarymy_dict={1:'A',2:'B',3:'C'}
print(max(my_dict)) # 3
Getting highest key value pair based on value of the dictionarymy_dict={'Raju':45,'Ronn':56,'Tom':50}
key_of_max_value = max(my_dict, key=my_dict.get)
print(key_of_max_value,my_dict[key_of_max_value])
Output is here
Ronn 56
We will use tuplemy_tuple=(6,1,12,7)
print(max(my_tuple)) #12
Using more than one list
my_list1=[4,7,8,9]
my_list2=[5,1,1]
print(max(my_list2,my_list1)) # [5, 1, 1]
More than two lists
my_list1=[4,7,8,9]
my_list2=[5,1,1]
my_list3=[6,1,-3]
print(max(my_list2,my_list1,my_list3)) # [6, 1, -3]
Here comparison is done from left to right and based on the position of the first highest element the list is returned as maximum. my_list1=[4,7,8,9]
my_list2=[4,1,1]
my_list3=[4,1,-3]
print(max(my_list2,my_list1,my_list3)) # [4, 7, 8, 9]
my_list1=[4,2,3,7,8,9]
my_list2=[5,1,100]
print(max(my_list2,my_list1,key=sum)) # [5, 1, 100]
Using Len
my_list1=[4,2,3,7,8,9]
my_list2=[5,1,100]
print(max(my_list2,my_list1,key=len)) # [4, 2, 3, 7, 8, 9]
def last_digit(my_list):
return my_list[-1] # last digit
my_list1=[4,2,3,7,8,9]
my_list2=[25,41,1]
print(max(my_list2,my_list1,key=last_digit)) #[4, 2, 3, 7, 8, 9]
min() Iterator
any()
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.