Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

401
Visualizações
What is Duck Typing in Python?
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda