Type System

Language Matrix

Category Static Dynamic
Strong C,C++,Java, Python, Ruby
Weak None JavaScript, Perl

Dynamic Type system

In a dynamic type system objects types are only resolved at runtime.

def add(x, y):
    print(x + y)
add(1, 2) # add int
add(10.1, 11.2) # add float
add("abc", "xyz")# add string
add([1, 2], [3, 4]) # add list
3
21.299999999999997
abcxyz
[1, 2, 3, 4]

Strong type system

Common definition is that the language will not in general implicitly convert objects between types

def add(x, y):
    print(x + y)
add("This is string", 10)  # This leads to error     
print(x + y)
TypeError: must be str, not int

Note: The exception being the conversion to bool used for if statements and while-loop predicates.

Object references (variables) has no types

x = "abc"  # x is binded to string
print(x)
x = 1  # x can be rebinded to integer
print(x)
abc
1

Python Home