Adding item to a list with slice in python

If you have been coding for a while in python you already know you can add an item in a list using

where list here is a variable that contains list of variables, append is a function and as parameter you will input the value you want to add at the end of the list.

However, you can’t add a value by stating an index number that has not been defined already.

But you can use slice to add that with trick. Look at the screen shot, it’s pretty self explanatory!

append, slice technique, python