Variables and data types
We call variable to a symbolic name that refers to an object. They act as memory containers for storing data values and are created when you assign a value to them using the assignment operator <-
or =
. For example, x <- 5
assigns the integer value 5 to the variable x
.
The value stored in a variable can change or vary throughout your program and can be any data type such as integers, strings, or lists. You will see different data types further in this section.
<- "Jean Golding"
name <- 27
age <- 76.4 weight
Chosing the correct name for a particular variable is an important task as a non-descriptive name (or worse, an incorrect name) will be very confusing for you and anyone reading your code. For instance, for a variable which contains a number representing a distance in miles, avoid shortened names like dm
, distm
or d
and instead use a name like distance_miles
. Remember, code will be written once but read many times so make it easy to read.