Duck typing

Photo by Simon Infanger on Unsplash

If it walks like a duck, quacks like a duck, then it is probably a duck!

Python is a dynamic language, which means it executes many programming behaviors (such as duck typing) at runtime.

Duck typing is simply looking at the behavior of an object to determine its type. In contrast, Normal typing looks at the type of an object to determine its behavior.

In the following example, we have a duck and a robot class.

Output:

Quack Quack Quack
I Quack too!

Both quack! Does it mean that the robot is a duck?
The idea is to determine the type of object based on its behavior, hence the abductive reasoning.

Sayonara!