Find the greatest number in a list of numbers

后端 未结 7 2064
我在风中等你
我在风中等你 2020-11-29 02:04

Is there any easy way or function to determine the greatest number in a python list? I could just code it, as I only have three numbers, however it would make the code a lot

7条回答
  •  广开言路
    2020-11-29 02:42

    You can actually sort it:

    sorted(l,reverse=True)
    

    l = [1, 2, 3]
    sort=sorted(l,reverse=True)
    print(sort)
    

    You get:

    [3,2,1]
    

    But still if want to get the max do:

    print(sort[0])
    

    You get:

    3
    

    if second max:

    print(sort[1])
    

    and so on...

提交回复
热议问题