How does the max() function work on list of strings in python?

前端 未结 3 1507
攒了一身酷
攒了一身酷 2020-11-29 10:06

I have a list:

list1 = [123, \'xyz\', \'zara\', \'abc\']
print \"Max value element : \", max(list1);

It gives:

Max value e         


        
3条回答
  •  抹茶落季
    2020-11-29 10:47

    list1=['2020','4','890','70','891','898']
    max(list1)
    

    --> returns 898

    in case of only numbers enclosed as string, it will compare the first maximum digit, if there are two(in this case: three which start with 8)-

    it will look for second digit of same number and continue to compare till it find the bigger one. hence return 898

提交回复
热议问题