What is a dynamically typed language?

Before we understand a dynamically typed language, we should learn about what typing is. Typing refers to type-checking in programming languages. In a strongly-typed language, such as Python, “1” + 2 will result in a type error since these languages don’t allow for “type-coercion” (implicit conversion of data types). On the other hand, a weakly-typed language, such as Javascript, will simply output “12” as result.

Type-checking can be done at two stages -

  • Static - Data Types are checked before execution.
  • Dynamic - Data Types are checked during execution.

Python is an interpreted language, executes each statement line by line and thus type-checking is done on the fly, during execution. Hence, Python is a Dynamically Typed Language.

It’s often the case that an algorithm relies on operations that exist for many different types. Sorting is one important example. Dynamic typing is a straightforward way of not having to encode the same algorithm multiple times for different types. In statically typed languages, the simplest code will only work with specific types. You have to do something more complex, like macros (C), inheritance based polymorphism (C++/C#/Java), interfaced based polymorphism (Go), templates (C++/Java) to get code that can work with multiple types with common operations.