Basic Variable Types
Introduction to Variable Types
One of the first things we said about Julia, is that it is an optionally typed language. That is, we can write code without specifying the type of each variable.
For example, we can do the following:
a = 1 + 1
typeof(a) # Int64
a = "Hello"
typeof(a) # String
Not that the variable
a was first an
Integer, then a
String, and we didn’t have to be explicit about that. We just assigned corresponding values, and the language took care of whatever was needed.
Even though this kind of behavior is valid, we can’t go very far by ignoring what is happening under the hood with variable types.
So, even on a first approach to the language, it is a good idea to know something about variable types.
The Julia type system is very complex indeed, and in this first approach we will only cover the most basic types, their conversion, and some common gotchas.