diff options
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)) |