Dynamic vs static
Last edited
When decisions get resolved is the core difference
static- compile/load time (static)dynamic- runtime
Below are all the examples that make a language dynamic.
Each instance below is just “which decision is being deferred to runtime”.
The more decisions deferred to runtime instead of resolved at compile time, the more dynamic the language.
Dynamic typing
Python interpreter does type checking only as code runs, and the type of a variable is allowed to change over its lifetime.
A PERFECT example of this is below.
if False:
1 + "two" # This line never runs, so no TypeError is raised
else:
1 + 2
3
>>> 1 + "two" # Now this is type checked
TypeError: unsupported operand type(s) for +: 'int' and 'str'This code clearly has a bug in it, but because the type checking only happens at runtime (when the line of code is run), it doesn’t raise and error.