diff options
| author | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-07-14 16:59:46 +0300 |
|---|---|---|
| committer | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-07-14 16:59:46 +0300 |
| commit | 4d13762c095d650687de64816c589be25b56daa0 (patch) | |
| tree | 17de451178a15cdf97bcef00d89ab6d8af3adad0 /python | |
| parent | 4e0e2063e7b0141099b36adfc537e98f3b667695 (diff) | |
| download | linkeysearch-4d13762c095d650687de64816c589be25b56daa0.tar.gz linkeysearch-4d13762c095d650687de64816c589be25b56daa0.tar.bz2 linkeysearch-4d13762c095d650687de64816c589be25b56daa0.zip | |
unrelated scripts (sorry)
Diffstat (limited to 'python')
| -rw-r--r-- | python/unrelated/obj.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/python/unrelated/obj.py b/python/unrelated/obj.py new file mode 100644 index 0000000..c20502f --- /dev/null +++ b/python/unrelated/obj.py @@ -0,0 +1,71 @@ +# Animal +# base class +class Animal: + + def __init__(self, name, age): + self.name = name + self.age = age + + def preview(self): + print(f"{self.name} is a {self.creature} of {self.age} years old") + + + +# Dog +# extends Animal +class Dog(Animal): + + voice = 'woof! ~@_@~' + + def __init__(self, name, age): + self.name = name + self.age = age + self.creature = 'dog' + + def speak(self): + print(self.voice) + + + +# Cat +# extends Animal +class Cat(Animal): + + voice = 'meao!! >^_^<' + + def __init__(self, name, age): + self.name = name + self.age = age + self.creature = 'cat' + + def speak(self): + print(self.voice) + + +# functions +# --- -- -- - - - + +def newLine(): + print(" ") + +def attrs(obj): + for attribute, value in obj.__dict__.items(): + print(f"{attribute}: {value}") + + +# instances +# --- -- -- - - - + +d = Dog('Ersi', 8) +r = Cat('Riri', 10) + +d.preview() +d.speak() +attrs(d) + +newLine() + +r.preview() +r.speak() +attrs(r) + |
