+ 1

New question about python string

What's different between [:] and [ ]?

10th Jul 2018, 3:50 PM
Arash Abdous
Arash Abdous - avatar
3 Answers
+ 4
[:] is used for get the all elements of any list and [] is ued for create empty list. e.g= x=[1,2,3,4] z=(x[:]) #now z=[1,2,3,4] x=[] #empty list. print(x) #output=[]
11th Jul 2018, 10:55 AM
Maninder $ingh
Maninder $ingh - avatar
+ 2
[:] is a slice (shallow copy) of an existing list. [] is an empty list deckarstion: b = [1,2,3] a = b[:] #now a is [1,2,3], so a == b but a is not b. c[] #declares an empty list c.
10th Jul 2018, 8:00 PM
strawdog
strawdog - avatar
0
Thx a lot
5th Aug 2018, 8:06 AM
Arash Abdous
Arash Abdous - avatar