-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdog_oop.py
More file actions
46 lines (31 loc) · 1.03 KB
/
dog_oop.py
File metadata and controls
46 lines (31 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# OOP - 4 pillars of OOP
# Inheritence
# Polymorphism
# Encapsulation
# Abstraction
#Here we are creating the class called "Dog"
class Dog:
animal_kind = "canine" # class variable
def __init__(self, name, color): # Initializing the class
self.name = name
self.color = color
# Here we are creating the method of barking
def bark(self): # Method variable inside the class
return "Woof Woof"
# Here we are creating the method of sleeping
def sleep(self):
return "ZzZzZzZz"
# Here we are creating the method of breathing
def breath(self):
return "*Breathing*"
# Here we are creating the method of running
def run(self):
return "Wouuuuf wuuuuf"
# Here we are creating the method of eating
def eat(self):
return "NoM NoM NoM"
fido = Dog("canine", "white") # Creating an object of our class
print(fido.color) # Printing an attribute of our class
lucy = Dog("lucy", "brown")
print(lucy.color)
# Create a method inside for sleep, breath, run, eat