File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff 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```
You can’t perform that action at this time.
0 commit comments