Julia Variables

Julia Variables are used to store values or data under named locations. You can use the variable name to access its value.

Variables are the parameters that define the state of a program.

The syntax to declare a variable is

variable_name = value
ADVERTISEMENT

In the following example, x is a variable and 10 is assigned to it.

julia> x = 10
10

julia> x
10

After assigning the variable a value, we can access the value stored in the variable using the variable identifier.

There is no need to explicitly specify a datatype to the variable. Based on the value you are assigning to the variable, the datatype is assigned.

julia> x = 10
10

julia> typeof(x)
Int64

Rules to name a variable

  1. Variable names must begin with a letter (A-Z or a-z), underscore, or a subset of Unicode code points greater than 00A0.
  2. Subsequent characters may also include ! and digits (0-9 and other characters in categories Nd/No), as well as other Unicode code points: diacritics and other modifying marks (categories Mn/Mc/Me/Sk), some punctuation connectors (category Pc), primes, and a few other characters