Skip to content

Instantly share code, notes, and snippets.

@AntiKnot
Created April 29, 2020 17:26
Show Gist options
  • Select an option

  • Save AntiKnot/4b23667a5f49e6f18c504cb66d76e578 to your computer and use it in GitHub Desktop.

Select an option

Save AntiKnot/4b23667a5f49e6f18c504cb66d76e578 to your computer and use it in GitHub Desktop.
python sort; python内置排序
l1 = [1, 2, 3]
l2 = list.sort(l1)
l3 = l1.sort()
l4 = sorted(l1)
def myprint(l):
print("{}, id:{}".format(l, id(l)))
return 0
if __name__ == '__main__':
myprint(l1)
myprint(l2)
myprint(l3)
myprint(l4)
"""
[1, 2, 3], id:4487356296
None, id:4485415016
None, id:4485415016
[1, 2, 3], id:4487356360
"""
@AntiKnot
Copy link
Copy Markdown
Author

sorted 返回排序后新的列表对象
sort 在修改原列表对象

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment