Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

399
Vistas
What is Duck Typing in Python?
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda