What is the use of duck typing?

What is the use of duck typing in python mcq and its answer is provided on this page.

Duck Typing is an application of duck test, "If it walks like a duck and it quacks like a duck then it must be a duck", to determine whether an object can be used for particular purpose.

Duck typing means try the method on object without checking the objects type to see if it fits the parameters type.

What is the use of duck typing mcq

Que. What is the use of duck typing?
a. More restriction on the type values that can be passed to a given method
b. Makes the program code smaller
c. Less restriction on the type values that can be passed to a given method
d. No restriction on the type values that can be passed to a given method
Answer : c
Explanation : In Python, any set of classes with a common set of methods can be treated similarly. This is called duck typing. Hence duck typing imposes less restrictions.


Comments