[Solved] Can you access attributes that were created with the init method from other methods in the class? [closed]


Use self:

class MyClass:
    def __init__(self):
        self.name="John"
    def other_method(self):
        print(self.name)

other_method will print “John”.

solved Can you access attributes that were created with the init method from other methods in the class? [closed]