-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduck_typing.py
More file actions
35 lines (24 loc) · 788 Bytes
/
duck_typing.py
File metadata and controls
35 lines (24 loc) · 788 Bytes
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
# duck typing = concept where the class of an object is less important
# than the method/attributes. class type is not checked
# if minimum methods/attributes are present."if it walks
# like a duck, and it quacks like a duck, then it must be a duck.
class Duck:
def walk(self):
print("This duck is walking")
def talk(self):
print("This duck is quacking")
class Chicken:
def walk(self):
print("This chicken is walking")
def talk(self):
print("This chicken is clucking")
class Person():
def catch(self, duck):
duck.walk()
duck.talk()
print("You caught the critter!")
duck = Duck()
chicken = Chicken()
person = Person()
# person.catch(duck)
person.catch(chicken)