>>> list1 = ['a','b','c','d','e','f','g','h', 'i', 'j', 'k', 'l'] >>> print list1[:5] ['a', 'b', 'c', 'd', 'e'] >>> print list1[-7:] ['f', 'g', 'h', 'i', 'j', 'k', 'l'] # Note how you can slice either positively or negatively. # When you use a negative number, it means we slice from right to left.
Here is what the above code is Doing:
1. We create a list called list1.
2. We print the first 5 elements of list1.
3. We print the last 7 elements of list1.