【发布时间】:2012-02-13 18:17:05
【问题描述】:
我正在使用 Python (3.2.2) shell 开发 Windows 7 操作系统。尝试学习我输入的语言并返回以下内容:
>>> 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'
===========================
似乎问题不在于编码,而在于程序的安装方式。
我已经安装,卸载并重新安装,但结果是一样的。在 Python 的 shell 准备好使用之前,我需要做些什么吗?
汉斯
【问题讨论】:
-
你在这里发布的是完整的代码吗?看起来您正在定义一个字典,然后尝试使用列表表示法访问它。您应该在这里看到语法错误。试试 cast = ["cleese","Palin","Jones","Idle"]。注意 '[' 而不是 '{'