Python Sort() method

后端 未结 4 480
感情败类
感情败类 2020-12-11 09:22

I am starting to learn Python.

Can someone explain why sort() returns None?

alist.sort()            ## correct
alist = blist.sort()    ## NO incorrec         


        
4条回答
  •  既然无缘
    2020-12-11 09:50

    Answering to his question, it returns none because the method always returns None. When you use it, it automatically modifies the list, so it does not keep the original intact (ie it does not return a sorted copy of the list).

提交回复
热议问题