
2.6 Python Programming: A Modern Approach
ds_list_slice.py
months = ["January", "February", "March", "April",
"May", "June", "July", "August", "September", "October",
"November", "December"]
first_quarter = months[0:3]
first_quarter = months[3:6]
third_quarter = months[6:9]
fourth_quarter = months[9:12]
python ds_list_slice.py
["January", "February", "March"]
["April", "May", "June"]
["August", "September", "October"]
["October", "November", "December"]
Like strings, the lists are zero-based, so months[0:3] returns the rst three items of
the list, starting at months[0] up to but not including months[3].
If the left slice index is 0, you can leave it ...