Python sort后赋值 操作陷阱

x=[1,4,2,0]  

# 错误的方式,因为sort没有返回值
y=x.sort()    
type (y)     #NoneType  

#正确的方式
x.sort()
y=x[:]

 

posted @ 2016-08-02 10:05  ohword  阅读(695)  评论(0编辑  收藏  举报