+ 1
.insert
words = ["Python", "fun"] index = 1 words.insert(index, "is") print(words) ON LINE TWO AND THREE, THE VARIABLE INDEX = 1 SO LINE FOUR IS ACTUALLY words.insert(1, "is"), WHAT DOES THE 1 REALLY MEAN IF WE NOT INDEXING BECAUSE THAT "is" gets inserted between the two words
2 Risposte
+ 5
"is" gets inserted as the list's element number 1 (so the second element) and the remaining one(s) to the right get shifted by one. The only element is "fun", which gets located on the third position (list's element number 2).
+ 1
on the first line. "python" is in 0 index and "fun" is in 1 index..
on the third line. it basically inserts the string "is" in index 1 and the others move by 1.
It enables you to insert something at the given index.