Last active
August 29, 2015 14:04
-
-
Save waltervargas/e4d42f85ab302ce6e5b6 to your computer and use it in GitHub Desktop.
python inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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