+ 4
Why list slicing showing differences in string list and number list?
Based upon the code below , i don't understand * if a list is there say s, then is s[1:1] work * in code, why s[1:1] which is a list of strings changes but not n[1:1] which is list of numbers ? https://code.sololearn.com/cM64cXV2LZ6l/?ref=app
6 odpowiedzi
+ 5
The problem with your code is that you missed []. You have to assign a list or iterable to a list slice.
You should do something like this:
s = ['a', 'c']
n = [0, 2]
s[1:1] = ['b']
n[1:1] = [3]
print(s, n)
+ 4
Kartik Krishnan and ~ swim ~ thanks a lot 😀 I understood where i had gone wrong.
0
Help me