Skip to content
IT glossary
ProgrammingUpdated December 3, 2026

Dynamic typing

Динамическая типизация

With dynamic typing, a program checks what it can do with a value while it runs. A variable can refer to a number at one point and a string later.

What dynamic typing means

A dynamically typed language still has types. In Python, 42 is an integer and "42" is a string, even though they may look identical when printed. If a variable first refers to 42 and later to "42", the assignment does not change the integer into a string. It makes the name refer to a different value.

What happens at runtime

Consider a function that calls .strip() on its argument. In Python, the function does not need to declare that the argument is a string. When the call runs, Python looks up strip on the object it received. If the object has no such attribute, the lookup raises AttributeError at that point. A call in a branch that never runs will not trigger that error.

Static typing checks whether operations are allowed based on types known before execution. Those types can be inferred, so the lack of a type annotation does not tell you whether a language is dynamically typed. Conversely, adding annotations to Python can help a static checker catch mistakes without changing how ordinary function calls behave at runtime.

Example: one function, different inputs

def clean(value):
    return value.strip()

clean("  ready  ")   # 'ready'
clean(b"  ready  ")  # b'ready'
clean(42)            # AttributeError

Both str and bytes provide strip, so the first two calls succeed, but their results have different types. The third call fails because an integer has no strip method. If the function is meant to return text every time, accepting anything with strip is not enough: the function needs a clearer input contract.

Where it helps and what it does not guarantee

Python and JavaScript use dynamic typing. It is useful in scripts and in code that works with objects based on their behavior rather than their exact class. A helper that reads from a file-like object, for example, can work with both a disk file and an in-memory stream. The trade-off is that a mismatched value may go unnoticed until the relevant path runs. Tests, optional static checking, and validation at boundaries such as JSON inputs address different parts of that problem.

Dynamic typing is not the same as implicit conversion: JavaScript evaluates 2 + "3" to "23", while Python raises TypeError. It is also separate from how code is executed: a dynamically typed language can compile code to bytecode or machine code.

What interviewers look for

When asked to predict a snippet's behavior, explain which value reaches the operation, what the language does with it, and when any error surfaces. If asked how to prevent the error, distinguish an annotation that helps a checker from a runtime check that rejects bad input.