Today i was asked one question in interview that "If we define instance variable outside the class will it show any error".
class temp():
a=0
b=0
def __init__(self,*args):
temp.a = args[0]
temp.b = args[1]
if len(args)>2 and args[2]:
print 'extra',args[2]
def display(self):
print self.a,self.b,self.c
a = temp(4,9)
b = temp(5,3)
a.c = 20
a.display()
If i run above code i get value of c= 20. I came from c++ background and thought this would be error but not...why it is like that...why python allow to create variable outside class.