-
Notifications
You must be signed in to change notification settings - Fork 0
/
oop.py
65 lines (43 loc) · 1.29 KB
/
oop.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# class Dog():
# species = "Canabis"
# def __init__(self, name, age):
# self.name = name
# self.age = age
# def description(self):
# return f"{self.name} is {self.age} years old"
# def speak(self, sound):
# return f"{self.name} says {sound}"
# miles = Dog("Miles", 4)
# print(miles.description())
# print(miles.speak("woof woof"))
# class Car():
# def __init__(self, color, mileage):
# self.color = color
# self.mileage = mileage
# def __str__(self):
# return f"the {self.color} car has {self.mileage:,} miles"
# blue_car = Car("blue", 20_000)
# red_car = Car("red", 30_000)
# print(blue_car)
# print(red_car)
#creating new child classes of the Dog class
class Dog:
species = "Canis familiaris"
def __init__(self, name, age):
self.name = name
self.age = age
def __str__(self):
return f"{self.name} is {self.age} years old"
def speak(self, sound):
return f"{self.name} says {sound}"
class JackRusselTerrier(Dog):
def speak(self, sound="Arf"):
return super().speak(sound)
class Dachshund(Dog):
pass
class Bulldog(Dog):
pass
miles = JackRusselTerrier("miles", 4)
print(miles.speak("woof woof"))
print(miles.speak())
print(isinstance(miles, Dog))