我试着写一个小班,想根据重量对项目进行排序。提供了代码,
class Bird:
def __init__(self, weight):
# __weight for the private variable
self.__weight = weight
def weight(self):
return self.__weight
def __repr__(self):
return "Bird, weight = " + str(self.__weight)
if __name__ == '__main__':
# Create a list of Bird objects.
birds = []
birds.append(Bird(10))
birds.append(Bird(5))
birds.append(Bird(200))
# Sort the birds by their weights.
birds.sort(lambda b: b.weight())
# Display sorted birds.
for b in birds:
print(b)
当我运行程序时,我得到Python TypeError: sort() takes no positional arguments. 这里有什么问题?
慕神8447489
智慧大石
守着星空守着你
相关分类