sort() and reverse() functions do not work

后端 未结 4 614
轻奢々
轻奢々 2020-11-22 12:42

I was trying to test how the lists in python works according to a tutorial I was reading. When I tried to use list.sort() or list.reverse(), the in

4条回答
  •  Happy的楠姐
    2020-11-22 13:11

    A simple ascending sort is very easy, call the sorted() function. It returns a new sorted list:

    >>> sorted([66.25, 333, 333, 1, 1234.5])
    [1, 66.25, 333, 333, 1234.5]
    

    sorted() accept a reverse parameter with a boolean value.

    >>> sorted([66.25, 333, 333, 1, 1234.5], reverse=True)
    [1234.5, 333, 333, 66.25, 1]
    

提交回复
热议问题