typeerror 'builtin_function_or_method' object has no attribute '__getitem__'

Roman Davis picture Roman Davis · Oct 25, 2012 · Viewed 75.3k times · Source

Here's the code:

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.

Answer

Nathan Villaescusa picture Nathan Villaescusa · Oct 25, 2012

You need to change the brackets in The_End.insert[x + 1, y] to parenthesis.

The_End.insert(x + 1, y)

It's good practice in Python to use lowercase variable names. Uppercase is generaly used for classes.