python needs leaning stuff from other language
Emile van Sebille
emile at fenx.com
Thu Apr 2 19:07:02 EDT 2009
Esmail wrote:
> Diez B. Roggisch wrote:
>> online.service at ymail.com schrieb:
>>> python's list needs a thing list.clear() like c# arraylist
>>> and
>>
>> some_list[:] = []
>
> I agree that this is nice and clear, but as a relative newbie
> wouldn't
>
> some_list = []
This is different -- it creates a new list. Consider:
>>> some_list = [1,2,3]
>>> d = some_list
>>> d[1]
2
>>> some_list[:] = ['a','b','c']
>>> d[1]
'b'
>>> some_list = [1,2,3]
>>> d[1]
'b'
the [:] form allows references into the list to remain valid while the
direct assignment dopes not.
Emile
>
> be also acceptable (and pythonic?)?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list