繁体   English   中英

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

[英]typeerror 'builtin_function_or_method' object has no attribute '__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]

这段代码应该是Pascal的三角形。 错误发生在第六行。

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

The_End.insert(x + 1, y)

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

你需要括号而不是[]

The_End.insert(x + 1, y)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM