Python – Adding elements to List without using append or extend method

Can we add elements to a list object without using append or extend methods of list. Lets check with an example. 

We can see it is not possible because memory allocation for list object in python happens at run time. So when the list L is created with three elements and try to access 4th index location it gives index out of range error because there is no object defined after 3rd location.

Now the question is how to add elements without using any methods of a list object. Is it possible? Yes it is by using list slicing.

We can see in above examples the list elements are added without using append or extend methods and by using list slicing technique. So if we want to emulate the append method we can do like below. This is how our append method in list works.