Try out the following pieces of code
#Instance variableclass A:def __init__(self):self.x = 22a = A()print a.x#Local variable, only accessible inside init and vanishes afterwardsclass A:def __init__(self):x = 22a = A()print a.x#x is an instance variableclass A:x = 22def __init__(self):return Nonea = A()b = A()a.x = 15print a.x, b.x
Comments
Post a Comment