I found this quirk while checking out how to use super
.
In [1]: super?
Init signature: super(self, /, *args, **kwargs)
Docstring:
super() -> same as super(__class__, <first argument>)
...
Note that the first example uses __class__
directly.
And somehow, __class__
can be used inside instance methods:
class Test():
def __init__(self):
print(__class__)
def foo(self):
print(__class__)
def bar(self):
print(bar)
t = Test() # <class '__main__.Test'>
t.foo() # <class '__main__.Test'>
t.bar() # NameError: name 'bar' is not defined
Can anyone explain why this is the case?