One of the nice things is that you can access lists of the items separately or in groups, through indexing and slicing. The radio is done (as in many other languages) hanging brackets index to the list. (Note that the first element has index 0).
print name [1], name [0] # print "Mine Sweeper"
name [0] = "Smith"
The slicing is almost like the indicative, except that write-off is the index of the result is to end with a colon ( : ) to separate them:
x = ["spam," "spam," "spam," "spam," "spam," "eggs", "and", "spam"]
print x [5:7] # Print the list ["eggs", "and"]
Note that the end is non-inclusive. If there is an index, it means you want everything in that direction. For example, list[:3] means "the beginning of each item list until the element 3 is not included "(You could argue that actually means the item 4, as part of the count to 0 ... oh well). list[3:] On the other hand, would mean "each element of list , starting from the 3 (inclusive) to the last, inclusive. " To get really interesting results, you can also use negative numbers: list[-3] is the third element from the end of the list ... About indexing, you might be interested to know that the built-in function len gives the length of a list.
Bookmarks