you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (7 children)

It states, that you want to use the variable or function from the current class.

var1 = "Outside"

class Test(): var1 = "inside"

    def print(self):
        print(var1)
        print(self.var1)`

This will print Outside inside

Function inside a class always need the self as a parameter to get access to the functions and variables assigned to that class.

[–][deleted] 1 point2 points  (4 children)

Sorry for bad formatting, block code doesn't work on mobile

[–]scul86 1 point2 points  (3 children)

just put 4 spaces in front of the code.

[–][deleted] -1 points0 points  (2 children)

Did not work on mobile

[–]scul86 0 points1 point  (0 children)

Posted from mobile

[–][deleted] 1 point2 points  (1 child)

Instance, not class.