What is Duck Type in Python? tccicomputercoaching.com

Page 1

What is Duck Type in Python? tccicomputercoaching.com As per Technical Definition: Duck typing in computer programming is an application of the duck test—"If it walks like a duck and it quacks like a duck, then it must be a duck"—to determine if an object can be used for a particular purpose. Actually it is not a python exclusive feature, since almost every dynamic language presents that behaviour.

Duck typing is a feature of a type system where the semantics of a class is determined by his ability to respond to some message (method or property). class Duck: def quack(): print('Quack!') class Goose: def quack(): print('Quack') Goose().quack() >> Quack! Duck().quack() >> Quack!


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.