Foo class only
Each
print(Foo.bar)
print(Foo().bar)
print(Foo.Bar.bar)
print(Foo.Bar().bar)
in
A, B, C, D
should be output.
I don't know where to start. Even if I put the print function in the bar and bar functions in Foo, only the reference value comes out and I can't find the answer.
python
You can do it as below.
class Foo():
bar='A'
def __init__(self):
self.bar='B'
class Bar():
bar='C'
def __init__(self):
self.bar='D'
print(Foo.bar)
print(Foo().bar)
print(Foo.Bar.bar)
print(Foo.Bar().bar)
© 2024 OneMinuteCode. All rights reserved.