my_frind = ['曹大鹏','王姐','李妍']
a = ['ab','fg','cg']
b = a.sorted()
print(b)
AttributeError: 'list' object has no attribute 'sorted'
sort()是方法,sorted()是函数,方法是调用,函数进行数据传递
a = ['ab','fg','cg']
print(sorted(a))
本文深入探讨了Python中列表排序的方法与函数的区别,演示了如何使用sort()方法和sorted()函数对列表进行排序,并通过实例解释了常见错误AttributeError的原因。
my_frind = ['曹大鹏','王姐','李妍']
a = ['ab','fg','cg']
b = a.sorted()
print(b)
AttributeError: 'list' object has no attribute 'sorted'
sort()是方法,sorted()是函数,方法是调用,函数进行数据传递
a = ['ab','fg','cg']
print(sorted(a))
2308
7208
1594

被折叠的 条评论
为什么被折叠?