Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7c327b2

Browse files
Update 03_Duck_Typing.MD
1 parent ad6e3df commit 7c327b2

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

‎Lecture_17/03_Duck_Typing.MD‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,35 @@ It is the concept where the class of an object is less important than the method
44
"If it walks like a duck and it quacks like a duck then it must be a duck".
55

66
```py
7+
class Duck:
8+
def walk(self):
9+
print("Duck is walking")
10+
def talk(self):
11+
print("Duck is quackng")
12+
class Person:
13+
def catch(self, Duck):
14+
Duck.walk()
15+
Duck.talk()
16+
print("You catch me")
17+
class Chicken:
18+
def walk(self):
19+
print("The chicken is walking")
20+
def talk(self):
21+
print("The chicken is talking")
22+
23+
duck = Duck()
24+
chicken = Chicken()
25+
person = Person()
26+
person.catch(duck)
27+
person.catch(chicken)
28+
29+
"""
30+
Output:
31+
Duck is walking
32+
Duck is quackng
33+
You catch me
34+
The chicken is walking
35+
The chicken is talking
36+
You catch me
37+
"""
738
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /