Lists

In Python, a list is a data type (its documentation is available here, https://docs.python.org/3.4/tutorial/datastructures.html#) that could be used to store elements in a sequence.

The topics discussed in this chapter can be difficult to grasp unless used in practice. Any example that is represented using this notation: >>> indicates that it could be tested using the Python interpreter.

A list may consist of strings, objects (discussed in detail in this chapter) or numbers, and so on. For instance, the following are examples of lists:

    >>> sequence = [1, 2, 3, 4, 5, 6]    >>> example_list = ['apple', 'orange', 1.0, 2.0, 3]

In the preceding set of examples, the sequence list consists of numbers between 1 and 6 while the example_list

Get Python Programming with Raspberry Pi now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.