The slice operator is unique to python and makes our lives as programmers MUCH easier. It is somewhat a combination between the range function and indexing. You can think of a slice as a section (or part) or a collection. We can takes "slices" of lists, strings and tuples. The basic syntax for a slice is square brackets with colons and integers inside "[0:1:2]".
The slice operator has optional arguments for if you decide to leave things blank. It will automatically start at index 0, stop at the end and step by 1 unless you declare otherwise. Here are some examples of the slice operator in use.
Insertion Using Slice
The slice operator is also useful for inserting elements into a list at a certain index. This specific functionality is only available for lists. To do this we simply use the slice operator with one colon and place the same integer on either side. At this index we will insert a specific item.
Unlike most other languages python supports negative indexing. What this means is that we can use negative integers to access values within a collection (str, list, tuple etc.). Negative indexing works similarly to positive indexing where -1 represents the last element in the list and -len(list) represents the first element. We can use negative indexing for slicing as well.