Skip to content

Instantly share code, notes, and snippets.

@1st
Created September 28, 2014 18:02
Show Gist options
  • Save 1st/016499a476e7a2b2d8f6 to your computer and use it in GitHub Desktop.
Save 1st/016499a476e7a2b2d8f6 to your computer and use it in GitHub Desktop.
Inheritance in Python
class A(object):
def aa(self):
print 'in A'
return self.__class__.__name__
class B(A):
def bb(self):
print 'in B'
return super(B, self).aa()
def cc(self):
print 'in B'
return self.__class__.__name__
>> # tests
>> a = A()
>> a.aa()
in A
'A'
>> b = B()
>> b.aa() # printed B class, not A
in A
'B'
>> b.bb()
in B
in A
'B'
>> b.cc()
in B
'B'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment