DEV Community

Bilal El Haj
Bilal El Haj

Posted on

Dynamically typed languages

Languages with dynamic typing do not require type declarations, but they also do not perform type inference. The types of variables are unknown until they have concrete values at runtime. For example, the Python function:

def function(x, y):
return x + y

can add integers, concatenate strings, concatenate lists, etc., and we cannot determine which will happen without actually running the program. It's possible that f will be called with strings at one point and integers at another, in which case x and y will hold values of different types at different times. This is why we say that values in dynamic languages have types, but variables and functions do not. The value 1 is clearly an integer, but x and y in the example may be anything.

Top comments (0)