Created
March 2, 2019 14:09
-
-
Save developer-sdk/40f53d20c80af5d7e5cb102ee0393cfd to your computer and use it in GitHub Desktop.
python class inheritance
This file contains hidden or 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
| #!/usr/bin/env python | |
| # -*- coding:utf-8 -*- | |
| class Parent(object): | |
| def __init__(self, name): | |
| self.name = name | |
| print('My name is {0}'.format(name)) | |
| def show(self): | |
| print('Parent show, {0}'.format(self.name)) | |
| class Child(Parent): | |
| def __init__(self, name): | |
| super(Child, self).__init__(name) | |
| def show(self): | |
| print('Child show, {0}'.format(self.name)) | |
| def main(): | |
| p = Parent('P') | |
| p.show() | |
| c = Child('C') | |
| c.show() | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment