May 16, 2013

Python: Dynamic and Strongly Typed Language


Python is both dynamically and strongly typed language.

Dynamic:
- i.e. Types are checked at run-time

Strongly:
- i.e. We can't intermingle variables with different type
         Javascript: var b = 'x' + 3, This will assign 'x3' into b
         While in python, you it would throw an exception



More into Dynamic Nature of Language:

When we declare a variable, we usually associate a type with that.
i.e. integer, float

For Example:

int a
float b

In STATICALLY typed language, variable type is fixed through out life cycle of program execution.

Assigning a = 's', ( integer typed variable to string would throw compile time error )

But, in python, it's dynamic nature.

Variable can hold any type of data through-out the life-cycle of program execution.

a = {'key':'value'} # first as dictionary
a = 'a' # now as String


So, during compile-time, type checks are skipped, Although, as its strongly typed language,
we can't intermingle two different type of variables.

It is up-to programmers test-suite to detect type errors.