菜鸟IT的博客 >> Python
sort()和sorted()的区别
sort():对原始列表进行排序
sorted():返回一个新的排序列表
# ——————————————————————————————
# ——————————————————————————————
groceries = ['milk', 'bread', 'tea']
new_groceries = sorted(groceries)
# new_groceries = ['bread', 'milk', 'tea']
print(new_groceries)
# groceries = ['milk', 'bread', 'tea']
print(groceries)
groceries.sort()
# groceries = ['bread', 'milk', 'tea']
print(groceries)
菜鸟IT博客[2022.10.23-17:45] 访问:482
※※相关信息专题※※
§【python技巧】