What is duck typing? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

What is duck typing?

It is difficult to really understand and become familiar with OOP. When I did revisions of OOP, I was often faced with the word โ€œduck typingโ€. I canโ€™t realize the meaning of the word very well. What is duck typing? What is the difference between duck typing and not? If possible, would you explain it with some examples in Python? This is not urgent. Please post when you feel like. Thanks.๐Ÿ™‚

10th Jun 2018, 5:31 PM
sumito_hz
sumito_hz - avatar
6 Answers
+ 2
BlazingMagpie Thank you very much. From the viewpoint of specification of programming language, does it mean unnecessity of object type declaration, doesnโ€™t it? Come to think of it, some language requires declaration of object type at all times. I confused with the style of programming at programmer side. Thanks!
10th Jun 2018, 7:17 PM
sumito_hz
sumito_hz - avatar
+ 4
Duck typing basically means that you can try using methods of objects without knowing the type of object. You can just tell object to fly and it will try to, but if it can't, you get error.
10th Jun 2018, 6:04 PM
BlazingMagpie
BlazingMagpie - avatar
+ 2
It seems like Iโ€™m still barking up the wrong tree. Is there another answer?
11th Jun 2018, 1:19 AM
sumito_hz
sumito_hz - avatar
+ 2
I think I roughly understand it through contents about the template of c++. Previous answer has been helpful for me. I got a hint. Thanks.
23rd Jun 2018, 6:06 PM
sumito_hz
sumito_hz - avatar
+ 2
Itโ€™s finished.๐Ÿ‘๐Ÿ‘๐Ÿ‘
24th Jun 2018, 7:41 AM
sumito_hz
sumito_hz - avatar
+ 2
You know thatโ€™s not all.๐Ÿ‘๐Ÿ‘๐Ÿ‘
24th Jun 2018, 10:45 AM
sumito_hz
sumito_hz - avatar