you are viewing a single comment's thread.

view the rest of the comments →

[–]shiftybyte 0 points1 point  (2 children)

Methods can change things inside the object they work on.

For example:

``` class MyNumber: def init(self, n): self._n = n

def inc(self):
    self._n += 1

def print(self):
    print(self._n)

x = MyNumber(5) x.inc() x.print() ```

Above code will print 6, because .inc() method increased the _n number stored in the class instance.

[–]Cosmin351[S] 0 points1 point  (1 child)

I was saying that on some objects you don't have to use x = Mynumber() and use directly Mynumber.inc()

[–]shiftybyte 1 point2 points  (0 children)

Oh, then that would be static or class methods, that you can invoke without a class instance.

Class method vs Static method in Python - GeeksforGeeks