python – int object has no attribute __getitem__

python – int object has no attribute __getitem__

The error:

int object has no attribute __getitem__

means that youre attempting to apply the index operator [] on an int, not a list. So is col not a list, even when it should be? Lets start from that.

Look here:

col = [[0 for col in range(5)] for row in range(6)]

Use a different variable name inside, looks like the list comprehension overwrites the col variable during iteration. (Not during the iteration when you set col, but during the following ones.)

This error could be an indication that variable with the same name has been used in your code earlier, but for other purposes. Possibly, a variable has been given a name that coincides with the existing function used later in the code.

python – int object has no attribute __getitem__

Some of the problems:

for i in range[6]:
            for j in range[6]:

should be:


Leave a Reply

Your email address will not be published. Required fields are marked *