How do I use different class values in both Python classes?

Asked 2 years ago, Updated 2 years ago, 18 views

class a:
    def aa(self):
        self.aaa = 1

class b:
    def bb(self):
        a.aa()

bbb = b()
bbb.bb()

In the b class, self.I wonder how to use the aaa value.

python

2022-09-20 22:05

1 Answers

I think it's because you've oversimplified the code, but I'm not sure what kind of role the class b should play with just the code you wrote.

Your question depends on whether class b inherits a, a as an instance variable, or a as a parameter.

Accordingly, in class b, what bb does is self.It can be set to aaa=1, it can be set to self.a.aa=1, or it can also be used to run aa of the class a received as a parameter.

If you think carefully about the direction you want, I think the direction of implementation will be concrete.


2022-09-20 22:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.