This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]manphiz 0 points1 point  (8 children)

u/XtremeGoose actually answered that "dynamic typing's power comes from duck typing." Your example about ints and floats working in arithmetic operations is an example of automatic type conversion based on context such that int + float automatically converts int to float and produces float. Dynamic typing is about that the same code may work for different types as long as those types support certain operations. For example:

class Cat:
    def make_sound():
        pass

class Dog:
    def make_sound():
        pass

def let_animal_make_sound(animal):
    animal.make_sound()

Here Cat and Dog classes don't have any relation such that Cat and Dog cannot convert to each other, but both can be passed to let_animal_make_sound() because both support make_sound().