difference between type(self) and self

0 votes
asked Jan 29 by anonymous
class C: 

    counter = 0
    
    def __init__(self): 
        type(self).counter += 1
x=C()
print(x.counter)
print(C.counter)
both the above print statement gives output 1 while if i use self.counter+=1 then the first print gives output 0 and second print gives 1, can anyone explain?

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...