AI engineering glossary · Python advanced

What is duck typing?

Duck typing: A style where an object's suitability is decided by whether it has the needed methods and attributes, not by its declared class. The saying is: if it walks and quacks like a duck, treat it as a duck.

Level: intermediateTopic: Python advanced

Duck typing: an example

len(x) works on a list, string or any object defining __len__, with no shared parent class required.

Related terms

More Python advanced terms

Where you learn it

Duck typing is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.