Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

difference between type(self) and self

0 votes
asked Jan 29, 2020 by anonymous
class C: 

    counter = 0
    def __init__(self): 
        type(self).counter += 1
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.