Chapter 3. Container Types
Container types are used to group objects together. The main difference between the different container types is the way individual elements are accessed and how operations are defined.
Lists
A list is, as the name hints, a list of objects of any kind:
L = ['a' 20.0, 5] M = [3,['a', -3.0, 5]]
The individual objects are enumerated by assigning each element an index. The first element in the list gets index 0. This zero-based indexing is frequently used in mathematical notation. Consider the usual indexing of coefficients of a polynomial.
The index allows us to access the following objects:
L[1] # returns 20.0 L[0] # returns 'a' M[1] # returns ['a',-3.0,5] M[1][2] # returns 5
The bracket notation here corresponds to the use of ...
Get Scientific Computing with Python 3 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.