Lists
Lists
• To remove a list element, you can use either the del statement if
you know exactly which element(s) you are deleting or the
remove() method if you do not know.
• #!/usr/bin/python
list1 = ['physics', 'chemistry', 1997, 2000]
print list1
del list1[2]
print "After deleting value at index 2 : " print list1
When the above code is executed,
• ['physics', 'chemistry', 1997, 2000]
After deleting value at index 2 : ['physics', 'chemistry', 2000]
Basic List Operations:
• Lists respond to the + and * operators much like
strings; they mean concatenation and repetition here
too, except
Python Expression
that the result
Results
is a new list, not
Description
a string.
Len([1,2,3]) 3 Length