Variables
Variables are labels that provide a descriptive name for some data that a program can read or modify. You can literally think of a variable as a label.
For example, let's assume there are a number of jars containing different colored jam. How do you know what flavor a specific jar contains? Hopefully, there is a label on the jar that is descriptive of its content.
The labels on the jar can change over time. For example, a jar might contain strawberry jam, but after that's gone it might be filled with peach jam. When the contents of the jar changes, a different label can be used to describe what's in it. Variables work in a similar fashion.
Creating variables
To create a variable, you need to do two things:
- Declare the variable
- Assign a value (data) to the variable
As an example, let's make a variable, foo
, and assign it the value bar
. The code to do this would be:
foo = "bar"
That single line of code declares a variable and assigns a string value to the variable. If you break it into several...