Dynamic typing means that in Python, types belong to objects, not to variable names. A variable can refer to an integer at one moment and a string the next — the name itself has no type annotation that the runtime enforces. This is in contrast to static typing (as in C, Java, or Rust), where the compiler checks that every variable holds only values of its declared type before the program runs.
Dynamic typing makes Python flexible and concise: you can write a function that works on any iterable without declaring interfaces, and you can prototype rapidly without committing to types up front. The cost is that type errors only surface at run time, potentially deep into execution. A misspelled attribute or an unexpected None can cause crashes that a static type system would have caught at compile time.
Python 3.5 introduced optional type hints (PEP 484) that let you annotate function signatures and variables with expected types. These annotations are ignored by the interpreter at run time but can be checked by external tools such as mypy or pyright. This "gradual typing" approach gives Python programmers the best of both worlds: dynamic flexibility where you want it, and static safety where you need it.
Related terms: Variable, Type Hint, Duck Typing
Discussed in:
- Chapter 3: Variables and Data Types — Dynamic Typing