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.


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.





Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Add and Search Word — Data structure design — Leetcode Challenge

Introduction into Annette Platform Community Edition

Home Assistant: Alpha Vantage

Integration of GitHub with Docker and Jenkins

Parallax Scrolling on Jinyong Campaign Page

How we keep running by running a slackbot.

Setting-up AWS ElasticSearch

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mansoor Aldosari

Mansoor Aldosari

More from Medium

Uploading python packages to be used by anyone with python

What is Variables?

Operators in Python

Python iterators & generators and why to use generators over list comprehensions (with examples and…