[Tutor] operator * of the list and tuple

Yang winglion1 at 163.com
Thu Aug 2 03:45:31 CEST 2007


tutor-request:
   I found this interesting question in a local forum,
and want to get a more detail explain of it:
>>> a = [[]]*5
>>> a
[[], [], [], [], []]
>>> a[0].append(3)
>>> a
[[3], [3], [3], [3], [3]]
>>> b = [[] for i in range(5)]
>>> b
[[], [], [], [], []]
>>> b[0].append(3)
>>> b
[[3], [], [], [], []] 
 This look something like pointer! I found it also work for tuple !
>>> l1=((1,2),(2,3))*5
>>> l1
((1, 2), (2, 3), (1, 2), (2, 3), (1, 2), (2, 3), (1, 2), (2, 3), (1, 2), (2, 3))

So, can somebody tell me how the * operator of list and tuple work,
and how can we make use of it?
 

				 
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Yang
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡winglion1 at 163.com
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2007-08-02





More information about the Tutor mailing list