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

21st Oct 2020, 1:37 PM
Nadirhan Şahin
Nadirhan Şahin - avatar
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]
21st Oct 2020, 1:44 PM
Seb TheS
Seb TheS - avatar
+ 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'
21st Oct 2020, 1:45 PM
QTWizard
0
Thanks for the answers. I got it.
21st Oct 2020, 2:18 PM
Nadirhan Şahin
Nadirhan Şahin - avatar