on-internet
← Community

Difference between __class__ and self.__class__ in instance method

Stack Overflow ·

In an instance method, both __class__ and self.__class__ refer to a class: class Foo: def hello(self): print(__class__) print(self.__class__) Foo().hello() Output: <class '__main__.Foo'> <class '__main__.Foo'> What's the difference between them? In what situations would they return different classes? (obj.__class__ vs type(obj) is already discussed here)

Comments

Sign in or sign up to comment and upvote.

No comments yet.