0
Why does this Python code insert a new value to a str list but raise exception for an integer list?
try: s = ['a', 'c'] n = [0, 2] s[1:1] = 'b' n[1:1] = 1 except: pass print(s[1], n[1]) # result: b 2
5 Respuestas
+ 3
slicing expects a sequence.
A String ls a sequence but an Integer is not.
+ 3
Jan Markus ich musste STUNDENLANG warten, damit du Erster bist
+ 3
Jan Markus
One python post has estimated 0.3 promille.
This explains how you feel.
+ 1
Jan Markus Thanks for the details! This snippet was a sololearn match challenge, that’s why it is a little bit strange. I just wanted to be sure I understand the solution.
0
Oma Falk Very clear and concise, thanks!