Saturday 12 October 2019

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!

In short Duck Typing is a way of programming in which an object passed into a function or method supports all method signatures and attributes expected of that object at run time.

To learn more about Computer Programming, Python, Object Oriented Languages, TCCI.

Call us @ 9825618292

Visit us @ www.tccicomputercoaching.com

No comments:

Post a Comment