Maximum in list python by R4R Team

Example -

then maximum in this list is 45

Program -

print("Enter all element in list")

#first way
for i in range(len(l)):
if l[i]>maximum:
print("Maximum in list is "+maximum)

#second way
print("Maximum in list is "+max(l))

output -

Enter all element in list
14 2 14 34 56 36 12 10 3
Maximum in list is 56
Maximum in list is 56

program to do this in a single line -

print(str(max(list(map(int,input("Enter number in listn").split()))))+" is maximum")

output -

Enter number in list
1 2 3 4 5
5 is maximum

In this program, we done this in one line and that's the beauty of the python programming language. How it works ? Firstly we take string input then with the use of split() we seprate the number then using map we type cast the string number to integer number then list is created then max() function is find the maximum out of them and print() function display that.

Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!