Can properties of the same class in python call their own methods?

I want to implement a function:

class FooBar():
    def __init__(self):
        self.foobar = foobar
    def foo(self):
        pass
    def bar(self):
        pass

a = Foobar()

after obtaining instance a, you can use the bar () method:

a.bar()

now, I want to let the foobar property and foo () method of an also use the bar () method:

a.foobar.bar()
a.foo().bar()

could you tell me how to write this? thank you

Mar.20,2021

classmethod and staticmethod learn about


you may have problems with object-oriented understanding

Menu