E
Esmail
Could someone help confirm/clarify the semantics of the [:] operator
in Python?
a = range(51,55)
############# 1 ##################
b = a[:] # b receives a copy of a, but they are independent
# The following two are equivalent
############# 2 ##################
c = []
c = a[:] # c receives a copy of a, but they are independent
############# 3 ##################
d = []
d[:] = a # d receives a copy of a, but they are independent
### 1 ### is the preferred, shorter way to do what ## 2 ## and ## 3 ##
do.
Am I correct with this?
Thanks.
in Python?
a = range(51,55)
############# 1 ##################
b = a[:] # b receives a copy of a, but they are independent
# The following two are equivalent
############# 2 ##################
c = []
c = a[:] # c receives a copy of a, but they are independent
############# 3 ##################
d = []
d[:] = a # d receives a copy of a, but they are independent
### 1 ### is the preferred, shorter way to do what ## 2 ## and ## 3 ##
do.
Am I correct with this?
Thanks.