Instance and Class variables in Python

#Instance and Class variables in Python

class Test:
    #Class variable
    i = 0
    
    #Instance Variable
    def __init__(self,c):
        Test.i = Test.i + 1
        self.j=c
        
    def printVal(self):
        print(self.i)
        
t1 = Test(10)
t2 = Test(20)
t3 = Test(20)
t4 = Test(20)
print(Test.i)
t1.printVal()
t2.printVal()

Comments