Dynamic typing

Dynamic typing (English dynamic typing ) denotes the fact that Type tests are carried out primarily for the duration of a program.

Examples

Python

Here is an interactive Python session:

A = 1 >>> # a contains by assigning an integer >>> A = 1.0 # adds the floating point number 1.0 and sets new value (with a different type) in a from A.upper >>> () # fails: a is not a string Traceback ( most recent call last):    File " ", line 1, in AttributeError: 'float ' object has no attribute 'upper ' >>> A # is the value of a from 2.0 >>> A = " now is a is a string" >>> A = 1 # Fails: Contents of a is now a string Traceback ( most recent call last):    File " ", line 1, in TypeError: can not concatenate 'str ' and 'int' objects A.upper >>> () ' NOW IS ON A STRING ' In Python, variables have no type, only the objects that reference the variables have a type. The error message " ... has no attribute 'upper ' " illustrates that the Python interpreter is not necessarily a string requires, but with any object with a method would be pleased upper (see duck typing ).

Boo

Example from the project site

D as duck d = 5 / / currently set to to integer. print d d = 10 / / It can do everything does to integer. print d d = " Hi there " / / sets it to a string print d d = d.ToUpper () / / It can do everything a string does. print d issue:

5 15 Hi there! HI THERE Explanation of Example

There the variable d is created and it is the data type assigned to duck. This is not a real data type, but only a kind of container that can accept other types of data. In the second row is assigned the integer value 5 d.

In line 6, it is assigned the string Hi there. In other programming languages ​​such as C # or C , this would now lead to a compiler error.

The Boo compiler, however, recognizes the data type of duck that the data type of the variable d may change.

250469
de