If you need a value more than once or you need the result of a calculation later, you have to give it a name to remember it. Computer scientists also say binding a value to a name or assign a value to a variable.
![]() | Binding |
|
Binding is the process of naming a value. | |
![]() | Variable |
|
Variables are names bound to values. You can also say that a variable is a name that refers to a value. | |
>>> EcoRI = 'GAATTC'
So the variable EcoRI is a name that refers to the string value 'GAATTC'.
The construction used to give names to values is called an assignment. Python, as a lot of other programming languages, use the sign = to assign value to variables. The two sides of the sign = can not be interchanged. The left side has always to be a variable and the right side a value or a result of a calculation.
![]() | Caution |
|---|---|
Do not confuse the usage of = in computer science and mathematics. In mathematics, it represents the equality, whereas in Python it is used to give names. So all the following statements are not valid in Python:
>>> 'GAATTC' = EcoRI
SyntaxError: can't assign to literal
>>> 1 = 2
SyntaxError: can't assign to literal
We will see later how to compare things in Python (Section 10.2).
| |