Today we start playing with data held in Lists. Lists are the workhorses of the Wolfram Language. They are ubiquitous in Wolfram Language programming and most of the time you will be operating on data held in Lists. Let’s dive in.

To create a list we use a pair of curly braces { } to enclose comma separated values.

In[]:=

{2,3,4,5,6,4}

Out[]=

{2,3,4,5,6,4}

Another way to create lists is to use the List[ ] function

In[]:=

List[2,3,53,2,3]

Out[]=

{2,3,53,2,3}

I like generating my lists automatically most of the time when it’s necessary

In[]:=

Range[10]

Out[]=

{1,2,3,4,5,6,7,8,9,10}

lets get a list containing even numbers by passing extra parameters into the Range[ ] function

In[]:=

Range[2,10,2]

Out[]=

{2,4,6,8,10}

Lists can hold anything! strings, numbers, images, other lists, etc.

In[]:=

"cat","dogs",12,34,3.3,{34,3,Plot[Sin[x],{x,0,10}]},

Out[]=

cat,dogs,12,34,3.3,34,3,

,

We can find the length of a list by using the Length function

In[]:=

Length[{3,4,2,5,"apples"}]

Out[]=

5

In[]:=

Length"cat","dogs",12,34,3.3,{34,3,Plot[Sin[x],{x,0,10}]},

Out[]=

7

## Exercise

Exercise

1. Why is the length of the last list above 7 and not 9 ?

We can get parts of lists by indexing using the [[ ]] operator

In[]:=

"cat","dogs",12,34,3.3,{34,3,Plot[Sin[x],{x,0,10}]},

[[2]]

Out[]=

dogs

Let’s use the indexing operator to access the first element of the sublist, i.e 34

In[]:=

"cat","dogs",12,34,3.3,{34,3,Plot[Sin[x],{x,0,10}]},

[[6,1]]

Out[]=

34

## Exercise

Exercise

2. Use indexing to get the Plot, i.e. the 3 element of the sublist

3. Use Range to generate even numbers up to 20

3. Use Range to generate even numbers up to 20

### Tip!

Tip!

You can suppress the output of an expression by placing a semicolon after it. e.g without the semicolon in the code cell below Range will print out it’s values.

In[]:=

Range[10];

See you in Part 4