Change List Items

0.0(0)
studied byStudied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/5

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 8:31 AM on 12/28/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

6 Terms

1
New cards

How do you change a single item in a list?

Refer to the index number.

Code:


fruits = ["apple", "banana", "cherry"]


fruits[1] = "kiwi"


Output: ["apple", "kiwi", "cherry"]

2
New cards

How do you change a range of item values?

Use slice indexing to replace multiple items.

Code:


fruits = ["apple", "banana", "cherry", "orange"]


fruits[1:3] = ["kiwi", "mango"]


Output: ["apple", "kiwi", "mango", "orange"]

3
New cards

What happens when you replace a range with more items than you removed?

The list expands to fit the new items.

Code:


fruits = ["apple", "banana", "cherry"]


fruits[1:2] = ["kiwi", "mango"]


Output: ["apple", "kiwi", "mango", "cherry"]

4
New cards

What happens when you replace a range with fewer items than you removed?

The list shrinks as items are replaced by a smaller set.

Code:


fruits = ["apple", "banana", "cherry"]


fruits[1:3] = ["watermelon"]


Output: ["apple", "watermelon"]

5
New cards

How do you use the insert() method to add an item at a specific index?

insert() adds an item without deleting anything.

Code:

fruits = ["apple", "banana"]

fruits.insert(1, "orange")

Output: ["apple", "orange", "banana"]

6
New cards

Code Challenge: What is the result of replacing [0:2] with ["X"] in the list ["a", "b", "c"]?

Code:


vals = ["a", "b", "c"]


vals[0:2] = ["X"]


Output: ["X", "c"]

Explore top flashcards

SENTENCE STARTERS!
Updated 1028d ago
flashcards Flashcards (52)
WWII
Updated 22d ago
flashcards Flashcards (35)
Word List 3 Math
Updated 1166d ago
flashcards Flashcards (20)
A2.2 Cell Organelles
Updated 884d ago
flashcards Flashcards (51)
Mechanics
Updated 624d ago
flashcards Flashcards (35)
SENTENCE STARTERS!
Updated 1028d ago
flashcards Flashcards (52)
WWII
Updated 22d ago
flashcards Flashcards (35)
Word List 3 Math
Updated 1166d ago
flashcards Flashcards (20)
A2.2 Cell Organelles
Updated 884d ago
flashcards Flashcards (51)
Mechanics
Updated 624d ago
flashcards Flashcards (35)