Python 3.3.2 (default, Aug 25 2013, 14:58:58)
[GCC 4.2.1 Compatible FreeBSD Clang 3.1 ((branches/release_31 156863))] on freebsd9
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 42
>>> a[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not subscriptable
>>> type(a)
<class 'int'>
>>>
其中一个变量是
int
,而你要做的是variable[0]
,这是用int
做不到的。在我建议让代码更加明确,例如:
这样你会发现奇怪的表达方式:
^{pr2}$意思是“点”的第一个元素。。。但是'点'是一个数字,里面没有元素!在
编辑 只是为了进入Python的风格:
相关问题 更多 >
编程相关推荐