Skip to content

Instantly share code, notes, and snippets.

@waltervargas
Last active August 29, 2015 14:04
Show Gist options
  • Save waltervargas/e4d42f85ab302ce6e5b6 to your computer and use it in GitHub Desktop.
Save waltervargas/e4d42f85ab302ce6e5b6 to your computer and use it in GitHub Desktop.
python inheritance
class FirstClass:
def setdata(self,value):
self.data = value
def display(self):
print(self.data)
class Bclass(FirstClass):
def concatena(self,arg):
self.data = arg + ' ' + self.data
class SecondClass(FirstClass, Bclass):
def display(self):
print ('current value = "%s"' % self.data)
if __name__ == '__main__':
x = FirstClass()
y = FirstClass()
z = SecondClass()
x.setdata("king arthur")
y.setdata(3.14159)
x.display()
y.display()
z.setdata('42')
z.concatena('Hola')
z.display()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment