Skip to content

Duck Typing

Easy — everyone uses thisGeneral Dev

ELI5 — The Vibe Check

Duck typing is the ultimate 'don't ask for a resume' approach. If it walks like a duck and quacks like a duck, it's a duck. Python doesn't check your type — it just tries to call the method and if it works, great. If not, KABOOM at runtime.

Real Talk

A typing paradigm common in dynamic languages (Python, Ruby, JavaScript) where an object's suitability is determined by the presence of methods and properties rather than its actual type. No explicit interface implementation is needed — if the object responds to the expected methods, it works.

Show Me The Code

# Python duck typing
class Duck:
    def quack(self): print("Quack!")

class Person:
    def quack(self): print("I'm quacking!")

def make_it_quack(thing):
    thing.quack()  # Works with anything that has quack()

make_it_quack(Duck())    # Quack!
make_it_quack(Person())  # I'm quacking!

When You'll Hear This

"Python's duck typing means you don't declare interfaces — just call the method and hope for the best." / "Duck typing is liberating until you pass the wrong object and get a cryptic AttributeError."

Made with passive-aggressive love by manoga.digital. Powered by Claude.