variable in Python
danb_83 at yahoo.com
Thu Apr 17 20:17:24 CEST 2003
Salvatore <artyprog at wanadoo.fr> wrote in message news:<b7lvbh$an3$1 at news-reader13.wanadoo.fr>...
> I have a little doubt.
> when you declare x = 3
<nitpick>There are no variable declarations in Python.</nitpick>
> does the variable x 'contains' the value 3 (like in Pascal)
> or does it contains an address which points to
> a memory place containing the value 3 ?
The latter: All variables in Python are pointers in disguise.
This is why, after executing
list1 = [0, 1, 2, 3]
list2 = list1
list2 = 0
list1 will be [0, 1, 2, 0] instead of [0, 1, 2, 3]. The assignment
"list2 = list1" copies a pointer to the list, not the contents of the
Note that I used a list instead of an int. With ints, the distinction
between value and reference semantics doesn't matter as much because
ints are immutable.
More information about the Python-list