我正在Python(3.2.2)shell的Windows 7操作系統上工作。努力學習我進入了語言,並返回以下:Python'set'對象不支持索引
>>> cast = {
'cleese',
'Palin',
'Jones',
'Idle'
}
>>> print (cast[1])
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
print (cast[1])
TypeError: 'set' object does not support indexing
>>> cast.append('Gilliam')
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
cast.append('Gilliam')
AttributeError: 'set' object has no attribute 'append'
==========================
似乎問題不在編碼中,而是在程序的安裝方式上。
我已經安裝,卸載並重新安裝,但resutl是一樣的。在Python的shell準備好使用之前,我需要做些什麼?
hans
是你已經張貼在這裏有什麼完整的代碼?它看起來像你正在定義一個字典,然後嘗試使用列表符號來訪問它。你應該在這裏看到一個語法錯誤。嘗試cast = [「cleese」,「Palin」,「Jones」,「Idle」]。注意'[''而不是'{' – timc