Slice as a copy

Fine, I have no choice, but to say I am an outman… I’ve no idea that python slice can be used as a copy of the original array, which, of course, can save us a tons of typing.

Again, when I talked about slice, I mean array slice, not immutable/optimized string slice.

>>> a = [ 1, 2, 3 ]
>>> b = a[ : ]

>>> id( a )
12822008
>>> id( b )
17547792

>>> id( a[ 0 ] )
505408872
>>> id( b[ 0 ] )
505408872

>>> a = ’123′
>>> b = a[ : ]

>>> id( a )
12578656
>>> id( b )
12578656

 

Comments

No comments so far.

Leave a Reply

 
(will not be published)
 
 
Comment
 
 

 

无觅相关文章插件,快速提升流量