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