2.6.1.3 Modifying a List
Python Programming
You can modify list items by accessing them via their index and assigning a new value. Example: Change the first item in the list to "Orange" and add a new fruit "Pineapple".
python
fruits = ["Mango", "Apple", "Banana"]
fruits [0] = "Orange"
fruits.append("Pineapple")
print(fruits)
# Output: [’Orange’, ’Apple’, ’Banana’, ’Pineapple’]Explanation: The code modifies the first element of the 'fruits' list to 'Orange', appends 'Pineapple' at the end, and prints the updated list.