Abstract
This chapter introduces a new concept: data structures. A data structure is a collection of data elements (such as numbers or characters, or even other data structures) that is structured in some way, such as by numbering the elements. The most basic data structure in Python is the sequence. Each element of a sequence is assigned a number—its position, or index. The first index is zero, the second index is one, and so forth. Some programming languages number their sequence elements starting with one, but the zero-indexing convention has a natural interpretation of an offset from the beginning of the sequence, with negative indexes wrapping around to the end. If you find the numbering a bit odd, I can assure you that you’ll most likely get used to it pretty fast.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsNotes
- 1.
It’s actually a class, not a function, but the difference isn’t important right now.
- 2.
Actually, from version 2.2 of Python, list is a type, not a function. (This is the case with tuple and str as well.) For the full story on this, see the section “Subclassing list, dict, and str” in Chapter 9.
- 3.
In case you’re interested, from Python 2.3 on, the sort method uses a stable sorting algorithm.
- 4.
The sorted function can, in fact, be used on any iterable object. You learn more about iterable objects in Chapter 9.
- 5.
Like list, tuple isn’t really a function—it’s a type. And, as with list, you can safely ignore this for now.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2017 Magnus Lie Hetland
About this chapter
Cite this chapter
Hetland, M.L. (2017). Lists and Tuples. In: Beginning Python. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-0028-5_2
Download citation
DOI: https://doi.org/10.1007/978-1-4842-0028-5_2
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-0029-2
Online ISBN: 978-1-4842-0028-5
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)