def size(self):
…
This defines a member size
of the class which is a method. So when you try to do self.size + 1
you are trying to add 1
to a method, which is exactly what the error is telling you.
Furthermore, you are also about to assign that result to self.size
, essentially overwriting the method, so that’s not what you want to do either.
Instead, you probably want to increment self.length
by one.
Note that it is recommended to implement the special method __len__
to allow people to use the len()
function with your object which is the standard way to get the length of an object. For example:
def __len__ (self):
return self.length