variable in Python

Dan Bishop danb_83 at
Thu Apr 17 20:17:24 CEST 2003

Salvatore <artyprog at> wrote in message news:<b7lvbh$an3$1 at>...
> Hello,
> 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[3] = 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 mailing list