list = [1, 2, 3] print list.append(4) ## NO, does not work, append() returns None ## Correct pattern: list.append(4) print list ## [1, 2, 3, 4]
list = ['a', 'b', 'c', 'd'] print list[1:-1] ## ['b', 'c'] list[0:2] = 'z' ## replace ['a', 'b'] with ['z'] print list ## ['z', 'c', 'd']
#!/usr/bin/python aList = [123, 'xyz', 'zara', 'abc'] aList.insert( 3, 2009) print "Final List : ", aList
list.insert(index, obj)