list vs tuple
deadmeat
root at [127.0.0.1]
Sat Mar 31 02:22:43 EST 2001
> Have you used other languages before coming to Python? I would
> think it would be confusing to people who were used to languages
> that have a reference/value inconsistency. Python is totally
> consistent (everything is a object, all names refer to objects).
No it's not. I come from a Pascal background, the behaviour noted in the
parent is what would happen if two pointers were made equal. To copy the
contents from one variable to another, a ^ is used to refer to the structure
at the pointer, not the pointer itself.
Python does not do that
>>> a = 1
>>> b = a
>>> a = 5
>>> b
1
>>> a = [1,2,3]
>>> b = a
>>> b[1] = 999
>>> b
[1, 999, 3]
It's dependant on datatype, which most people would think as inconsistant.
Example 2 is the same for function arguments, pass all lists to functions
with a [:] on the end to ensure your function doesn't modify your list
without the parent code knowing about it.
More information about the Python-list
mailing list