Next / Previous / Contents / TCC Help System / NM Tech homepage

11. Type list: Mutable sequences

To form values into a sequence, use Python's list type if you are going to change, delete, or add values to the sequence. For a discussion of when to use list and when to use tuple, see Section 12, “Type tuple: Immutable sequences”.

To create a list, enclose a list of zero or more comma-separated values inside square brackets, “[...]”. Examples:

[]
["baked beans"]
[23, 30.9, 'x']

You can also create a list by performing specific operations on each element of some sequence; see Section 11.2, “List comprehensions”.

Lists support all the operations described under Section 8.1, “Operations common to all the sequence types”. Methods available on lists are discussed in Section 11.1, “Methods on lists”.

There are a number of functions that can be used with lists as well: