这是我的代码:
bands = []
band = []
headline = input('Headline: ')
while band != "":
bands.append(band)
band = input('Band: ')
band.sort()
print(headline)
for band in bands:
print(band)用户需要输入一个姓名列表,并按字母顺序进行排序,但我一直收到这个错误
Traceback (most recent call last):
File "program.py", line 7, in <module>
band.sort()
AttributeError: 'str' object has no attribute 'sort'谁能帮帮我。
发布于 2017-08-30 16:27:18
您尝试对band进行排序,它是一个字符串,因此在Python语言中是不可变的。这可能是一个打字错误,而您想要bands.sort()
https://stackoverflow.com/questions/45955106
复制相似问题