From 87e2b74b18194060ed14e7744ed59d46f3c1b98a Mon Sep 17 00:00:00 2001 From: Prabhu Ramachandran Date: Wed, 22 Nov 2017 17:26:48 +0530 Subject: Add one example module. --- advanced_python/code/oop.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 advanced_python/code/oop.py 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)) -- cgit