Skip to content
Advertisement

Class variables not callable?

I’ve stumbled on what is probably a simple issue but I struggle to think of a solution. If I try to make a class variable that equates to a number or an array index they come up with these errors

JavaScript

and

JavaScript

JavaScript

JavaScript

This seems odd since I can set variables equal to ints and arrays elsewhere. What am I missing and what is the solution?

Advertisement

Answer

In both piece of code result and index are not methods, they are instance valiables. To make this code work it should look like this:

JavaScript

and

JavaScript

Also pay attention that there ia s misspelling in def __init__(sel): line in Do_something_else class. It should be def __init__(self):

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement