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

发表评论

电子邮件地址不会被公开。 必填项已用*标注