Defining variables
We have seen in the previous chapter how to use the REPL in order to execute computations and have the result displayed back to us. Julia even lends a helping hand by setting up the ans
variable, which automatically holds the last computed value.
Â
But, if we want to write anything but the most trivial programs, we need to learn how to define variables ourselves. In Julia, a variable is simply a name associated to a value. There are very few restrictions for naming variables, and the names themselves have no semantic meaning (the language will not treat variables differently based on their names, unlike say Ruby, where a name that is all caps is treated as a constant).
Let's see some examples:
julia> book = "Julia v1.0 By Example"
julia> pi = 3.14
julia> ANSWER = 42
julia> my_first_name = "Adrian"
Note
You can follow along through the examples in the chapter by loading the accompanying Jupyter/IJulia notebook provided with this chapter's support files.
The variables...