Array Creation
We create an array by wrapping the items in square brackets and separating them with commas. For example:
shopping = ["Apples", "Chocolate", "Bread rolls"]
This creates an array with the elements "Apples"
, "Chocolate"
, "Bread rolls"
and stores it in the variable shopping
.
Arrays can store any data type - we can have an array that contains only one data type, or an array that contains different data types. For example:
array = ["text", 123, True]
This array has three elements "text"
, 123
, and True
. Each element is of a different data type.
Instructions
Create an array with the values "Peter"
, "Tim"
, "Lucy"
in that order. And store it in a variable named colleagues
.
Print the value of the variable colleagues
.
Start programming for free
2/10