0
Can Someone Explain This? 2
Can Someone Explain This? I don't understand how this code works. Could you explain this? https://code.sololearn.com/cyeN660KbsPr/?ref=app
3 Respuestas
+ 3
list[a:a] = ... can be used to insert an iterables inside lists.
String is an iterable, it is a collection of characters, thus s[1:1] = "b" is possible.
But integer is not an iterable and thus n[1:1] = 1 results in error, but you can do n[1:1] = [1]
+ 2
The reason why s is affected because "b" is a str object, which is an iterable. Int objects are not iterables, you cannot assign them to a list.
Change the int value to an iterable like a string, it will works.
n[1:1]='a'
0
Thanks for the answers. I got it.