0
class A:
    def __init__(self):
        self.a=10


        
    def bvalue(self):
        self.b=20
         
    def add1(self):
        c=self.a+self.b
        print(c)
        
a1=A()
a1.add1()

ouput
 AttributeError: 'A' object has no attribute 'b'

Im decalring a=10 inside init mehthod and declaring b=20 inside another method, and using 3rd method im trying to add a+b. but why it's giving error? am i making any mistakes here?

1 Answers1

0

you should call method bvalue first before you call add1

try:

a1=A()
a1.bvalue()
a1.add1()
Aodan Jing
  • 21
  • 6