Python – Change List Items

1. What Does “Change List Items” Mean?

Changing list items means updating or replacing values inside a list.

Good news 😊
Lists in Python are changeable (mutable).

2. Change a Single List Item

You can change a list item by using its index number.

Example

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

fruits[1] = "mango"
print(fruits)

Output:

['apple', 'mango', 'orange']

3. Change Multiple List Items (Using Slicing)

You can change more than one item at a time.

Example

numbers = [10, 20, 30, 40, 50]

numbers[1:3] = [25, 35]
print(numbers)

Output:

[10, 25, 35, 40, 50]

4. Change Range with Different Size

You can replace items with more or fewer values.

Example (More Items)

colors = ["red", "blue", "green"]

colors[1:2] = ["yellow", "pink"]
print(colors)

Example (Fewer Items)

colors[1:3] = ["black"]
print(colors)

5. Change Last Item Using Negative Index

Example

animals = ["cat", "dog", "cow"]

animals[-1] = "goat"
print(animals)

6. Change Items Using Loop

You can also update items using a loop.

Example

numbers = [1, 2, 3]

for i in range(len(numbers)):
numbers[i] = numbers[i] * 2

print(numbers)

Output:

[2, 4, 6]

7. Common Beginner Mistakes

❌ Index Out of Range

fruits[5] = "grape"

✔ Fix:

print(len(fruits))

❌ Trying to Change Tuple (Not Allowed)

items = ("pen", "book")
items[0] = "pencil"

❌ Error because tuple cannot be changed.

8. Simple Practice Examples

Example 1: Change City Name

cities = ["Delhi", "Mumbai", "Chennai"]
cities[0] = "Kolkata"
print(cities)

Example 2: Update Marks

marks = [60, 70, 80]
marks[2] = 85
print(marks)

Example 3: Replace Multiple Items

nums = [1, 2, 3, 4]
nums[1:3] = [10, 20]
print(nums)

9. Summary (Change List Items)

✔ Lists are changeable
✔ Use index to change single item
✔ Use slicing to change many items
✔ Negative index works
✔ Be careful with index range

📘 Perfect for Beginner eBook

This chapter is ideal for:

  • Python beginner books

  • School & college students

  • Self-learners

If you want next, I can write:

  • Add List Items

  • Remove List Items

  • List Methods

  • List Exercises

Just tell me 😊

You may also like...