代碼
bicycles = {'zhang', 'shou', 'long'}
print(bicycles[0].title())
報錯
Traceback (most recent call last):
File "D:/python編程/run.py", line 2, in <module>
print(bicycles[0].title())
TypeError: 'set' object does not support indexing
糾正
錯誤顯示的是“元組”對象不支持索引;
但是列表支持索引;
a = {"a","b","c"} #這是元組,不支持索引
a = ["a","b","c"] #這是列表,支持索引,只要把花括號改成方括號就行