August 2019
Beginner
482 pages
12h 56m
English
As with strings, in order to get a single value from the list, you need to use its index in the square brackets after the value, as shown in the following code snippet:
>>> fruits[0]'banana'
You can also obtain a subset of list values by using slices: intervals of indexes that are defined by two numbers and separated by a colon. The numbers represent start and end indices; the former number is inclusive, but the latter number is not. If one or both numbers are missing, then Python assumes those to be the ends of the list. Here is an example:
>>> fruits[0:2]['banana', 'apple']>>> fruits[:2]['banana', 'apple']
In both cases, we're pulling the first two elements. In this case, it doesn't matter whether we include 0 or not.
This is exactly ...