typeerror 'builtin_function_or_method' 对象没有属性 '__getitem__' [英] typeerror 'builtin_function_or_method' object has no attribute '__getitem__'
本文介绍了typeerror 'builtin_function_or_method' 对象没有属性 '__getitem__'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码如下:
The_Start = [1,1]
The_End = [1, 1]
for z in range(20):
for x in range(len(The_Start) - 1):
y = The_Start[x] + The_Start[x + 1]
The_End.insert[x + 1, y]
print The_End
The_Start = The_End
The_End = [1, 1]
这段代码应该是用来制作帕斯卡三角形的.错误在第六行.
This code is supposed to make a Pascal's triangle. The error is on the sixth line.
推荐答案
您需要将 The_End.insert[x + 1, y]
中的括号更改为括号.
You need to change the brackets in The_End.insert[x + 1, y]
to parenthesis.
The_End.insert(x + 1, y)
在 Python 中使用小写变量名是一种很好的做法.大写通常用于类.
It's good practice in Python to use lowercase variable names. Uppercase is generaly used for classes.
这篇关于typeerror 'builtin_function_or_method' 对象没有属性 '__getitem__'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文