sort() and reverse() functions do not work

后端 未结 4 636
轻奢々
轻奢々 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条回答
  •  生来不讨喜
    2020-11-22 13:02

    This methods operate in place.

    This code works (python 3.x)

    a = [66.25, 333, 333, 1, 1234.5]
    a.sort()
    print(a)
    a.reverse()
    print(a)
    
    >>> 
    [1, 66.25, 333, 333, 1234.5]
    [1234.5, 333, 333, 66.25, 1]
    

提交回复
热议问题