+1 vote
in Class 12 by kratos

Give an example to update single or multiple elements of lists

1 Answer

+3 votes
by kratos
 
Best answer

You can update single or multiple elements of lists by giving the slice on the lefthand side of the assignment operator, and you can add elements in a list with the append( ) method. Following is a simple example:

!/user/bin/python

listl = [‘physics’, ‘chemistry’, 1997, 2000];

print “Value available at index 2 :”

print list[2]; list[2] = 2001;

print “New value available at index 2 :”

print list [2];

Note: append)) method is discussed in subsequent section.

When the above code is **, it produces the following result:**

Value available at index 2 :

1997

New value available at index 2 :

2001

...