Define a List
Lists help us organize two-dimensional data.
Create lists by placing elements inside square brackets ([]
):
A list can contain numbers (with or without units):
Dates:
Text strings:
Or even booleans:
A list must be coherent
Lists cannot contain different types of elements. Here are some examples of non-valid lists:
Units on lists must be consistent:
Creating lists from sequences
Create a list by specifying a sequence:
List Operations
You can apply an arithmetic operator to lists (+
, -
, *
, /
, etc.):
If you have two lists you can operate on each corresponding item like this:
This only works if both lists have the same number of elements.
You can also operate on lists with dates:
Or strings:
Or even using the not
boolean operator: