Very simple (and potentially stupid question) What is 'List Slicing' in python and can someone please give an example of list slicing.
Thanks !
Very simple (and potentially stupid question) What is 'List Slicing' in python and can someone please give an example of list slicing.
Thanks !
List slicing is creating a new list containing the requested elements.
a = ['spam', 'eggs', 100, 1234]
This means that the following slice returns a shallow copy of the list a:
>>> a[:]
['spam', 'eggs', 100, 1234]
An example would be accessing the first three items of an array like so:
arr[:3]
There are many other examples on this page: