0
這是我的代碼:按字母順序排列運行的代碼錯誤
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'
有人可以幫助我嗎?
是的,我試過,但我收到此錯誤 – Jako613
回溯(最近通話最後一個):在 bands.sort 文件「program.py」,第7行,( ) TypeError:在'str'和'list'的實例之間不支持'<' –
Jako613
對不起,我剛剛被推遲並在添加答案之前更改了我的代碼,並忘記了再次抱歉,您是對的.XD – Jako613