Dynamic type checking provides runtime execution safety.
- It analyzes the code after running it (after code execution)
- It discovers errors when the problematic code path is reached
- It happens implicitly
- It is enforced by the interpreter itself
Letβs consider the following Python function:
def process_user(user):
return user["age"] + 10Now, if we call the function and pass an invalid type for user["age"], it will throw a TypeError.
user = {"age": "twenty"}
process_user(user) # TypeErrorBecause "twenty" (string) cannot be added to 10 (integer).
This means Python stops invalid operations at execution.
