diff options
author | Prabhu Ramachandran | 2017-11-22 17:26:48 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2017-11-22 17:26:48 +0530 |
commit | 87e2b74b18194060ed14e7744ed59d46f3c1b98a (patch) | |
tree | 37ebe4faf66fc93e0c94dd15714de0d04e0c8a5d /advanced_python | |
parent | 97cc47ee334b81331d6bf1ef094ad9a88f78cd8d (diff) | |
download | python-workshops-87e2b74b18194060ed14e7744ed59d46f3c1b98a.tar.gz python-workshops-87e2b74b18194060ed14e7744ed59d46f3c1b98a.tar.bz2 python-workshops-87e2b74b18194060ed14e7744ed59d46f3c1b98a.zip |
Add one example module.
Diffstat (limited to 'advanced_python')
-rw-r--r-- | advanced_python/code/oop.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/advanced_python/code/oop.py b/advanced_python/code/oop.py new file mode 100644 index 0000000..d0cbc3f --- /dev/null +++ b/advanced_python/code/oop.py @@ -0,0 +1,30 @@ +class Animal: + def __init__(self, name): + self.name = name + + def greet(self): + return self.name + ' says greet' + + +class Mammal(Animal): + def __init__(self, name, legs): + super().__init__(name) + self.legs = legs + + +class Human(Mammal): + def __init__(self, name, legs=2): + super().__init__(name, legs) + + def greet(self): + return self.name + ' says hello' + + def speak(self): + print('My name is', self.name) + + +print(__name__) +h = Human('Sam') +print(h.greet()) +print(h.legs) +print(type(h)) |