instance attribute "a" defined outside __init__
Rio
inkprs at gmail.com
Wed Apr 1 17:26:43 EDT 2015
Hi, When running below code, I get error saying:
instance attribute "a" defined outside __init__
class Foo:
var = 9
def add(self, a, b):
self.a = a
self.b = b
print a+b
def __init__(self):
print 10
bar = Foo() # create object
bar.add(4, 7) # call method by object.method
print bar.var # access class variable
why the output prints:
10
11
9
why not serially?
9
11
10
More information about the Python-list
mailing list