+ 1
New question about python string
What's different between [:] and [ ]?
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=[]
+ 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.
0
Thx a lot