1.

Give an example to access values in lists.

Answer»

To access value in lists, use the square brackets for slicking along with the index or indices to obtain value available at that index. Following is a simple example :

# !/user/bin/python

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

list2 = [1, 2, 3, 4, 5, 6, 7];

print “list1 [0]:”,

list1 [0] print “list2[1 :5]:”, list2[1:5]

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

list1 [0]: physics

list2[1:5] : [2, 3, 4, 5]



Discussion

No Comment Found