python - typeerror 'builtin_function_or_method' 对象没有属性 '__getitem__'

标签 python typeerror

代码如下:

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]

这段代码应该是一个帕斯卡三角形。错误在第六行。

最佳答案

您需要将 The_End.insert[x + 1, y] 中的括号改为括号。

The_End.insert(x + 1, y)

在 Python 中使用小写变量名是一种很好的做法。大写通常用于类。

关于python - typeerror 'builtin_function_or_method' 对象没有属性 '__getitem__',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13075632/

相关文章:

python - 为 Python 显示简单的 OpenStreetMap 瓦片

python - 获取 <b> 标签中文本的下一个内容

javascript - React Js Uncaught( promise )TypeError : Cannot read property of undefined

javascript - 光滑的轮播未捕获类型错误: undefined is not a function?

python - 如何对具有混合数据类型的 pandas 数据框中的浮点(十进制)值进行舍入?

Python字符串实习

python - 如何获取 gitpython 中从当前到特定标签的所有提交

python - 嵌套列表/字典的最大值 - Python

Python - OrderedDict 中的字典理解不起作用

python - 将伪代码转换为 Python 时出错