# By default, Julia returns the output
2 + 3
5
Marie-Hélène Burle
A variable is a name bound to a value:
It can be called:
Or used in expressions:
You can re-assign new values to variables:
Even values of a different type:
You can define multiple variables at once:
These names are extremely flexible and can use Unicode character:
Admittedly, using emojis doesn’t seem very useful, but using Greek letters to write equations really makes Julia a great mathematical language:
Note how the multiplication operator can be omitted when this does not lead to confusion.
Also note how the mathematical constant π is available in Julia without having to load any module.
If you want to know how to type a symbol, ask Julia: type ?
and paste it in the REPL.
The only hard rules for variable names are:
if
, do
, try
, else
,π
) and keywords in use in a session.We thus get an error here:
LoadError: syntax: invalid assignment location "false" around In[24]:1
syntax: invalid assignment location "false" around In[24]:1
Stacktrace:
[1] top-level scope
@ In[24]:1
In addition, the Julia Style Guide recommends to follow these conventions:
The keyword ans
is a variable which, in the REPL, takes the value of the last computation:
10
To print the value of a variable in an interactive session, you only need to call it:
In non interactive sessions, you have to use the println
function:
Note the difference between single and double quotes:
ParseError: # Error @ ]8;;file:///home/marie/parvus/prog/mint/julia/In[30]#1:2\In[30]:1:2]8;;\ 'This is not a sring' #└─────────────────┘ ── character literal contains multiple characters Stacktrace: [1] top-level scope @ In[30]:1
We got an error here since '
is used for the character type and can thus only contain a single character.
Comments
Comments do not get evaluated by Julia and are for humans only.