MENU
Question -

Give an example to update single or multiple elements of lists



Answer -

You can update single or multiple elements of lists by giving the slice on the left-hand 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 executed, it produces the following result:

Value available at index 2 :
1997
New value available at index 2 :
2001

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×