How we can update a Python list element value?



Python list object is mutable. Hence it is possible to update the list object.

To update list, assign new value to any item by using it access. For example, if you want to set 4th item (index counting from 0) to double its earlier value,

>>> L1
[10, 50, 20, 9, 40, 100, 60, 30, 1, 56]
>>> L1[4]=L1[4]*2
>>> L1
[10, 50, 20, 9, 80, 100, 60, 30, 1, 56]

Item at 4th index has changed from 40 to 80.



Advertisements