2.5. Reassignment of variables

It is possible to reassign a new value to an already defined variable. This will destroy the reference to its former value and create a new binding to the new value. This is shown in Figure 2.2.

Figure 2.2. Reassigning values to variables

Note

In Python, it is possible to reassign a new value with a different type to a variable. This is called dynamic typing, because the type of the variable is assigned dynamically. Note that this is not the case in all programming languages. Sometimes, as in C, the type of variables is assigned statically and has to be declared before use. This is some way more secure because types of variables can be checked only by examining the source code, whereas that is not possible if variables are dynamically typed.