Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

398
Views
What is Duck Typing in Python?
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Duck typing or duck typing is a concept related to programming that applies to certain object- oriented languages, and that has its origin in the following sentence: " If it walks like a duck and talks like a duck, then it has to be a duck ."

And what relationship do ducks have with programming? Well, it is a simile in which the ducks are objects and talk/walk methods . In other words, if a given object has the methods that interest us, that is enough for us, its type being irrelevant.

Let's define a Pato class with a hablar() method.

 class Pato: def hablar(self): print("¡Cua!, Cua!")

And we call the method as follows.

 p = Pato() p.hablar() # ¡Cua!, Cua!

Nothing new so far, but we are going to define a llama_hablar() function, which calls the hablar() method of the passed object.

 def llama_hablar(x): x.hablar()

When Python enters the function and evaluates x.hablar() , it doesn't care what type x belongs to as long as it has the hablar() method. This is duck typing at its best.

If you want to go deeper into the subject here I leave you an extensive tutorial talking about " Duck typing "

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!