Chapter Processing Lists and Tuples

Lists and tuples are two of Python's compound data types, also called container objects. Compound data types group collections of data.

Python has several kinds of compound data types. Lists and tuples are sequence types because each element of data is numbered sequentially, starting with 0. Sequence types support operations called indexing and slicing for working with individual elements or subsets of elements. You can find out about indexing and slicing in Chapter 6.

A sequence data type is good when you want to operate on all the elements in a collection or when the order of elements in a collection is important. (In contrast, the dictionary data type—a mapping type—is for random access to elements, and a set is for comparing collections of objects. Dictionaries and sets are covered in Chapter 9.)

This chapter shows you the syntax for lists and tuples, when to use them, how to work with elements inside them, how to use them in loops, and how to avoid some of the common errors programmers make when working with them.

Was this article helpful?

0 0

Post a comment