Title here
Summary here
In Julia, variables are implicitly declared when they are assigned a value. The type of the variable is inferred by the compiler, but can also be explicitly specified.
# Variables can be declared and initialized in one line
a = "initial"
println(a)
# You can declare multiple variables at once
b, c = 1, 2
println(b, " ", c)
# Julia will infer the type of initialized variables
d = true
println(d)
# Variables declared without initialization are assigned
# the value 'nothing'. For numeric types, use the 'zero' function
e = zero(Int)
println(e)
# Julia doesn't have a special syntax for short declaration
# All assignments are done with '='
f = "apple"
println(f)
To run the program, save it as variables.jl
and use the julia
command:
$ julia variables.jl
initial
1 2
true
0
apple
In Julia:
var
keyword or equivalent.zero
function is used to initialize numeric variables to their zero value.=
.:=
.println
for printing with a newline, similar to Go’s fmt.Println
.Julia’s type system is quite different from statically typed languages, offering flexibility while still allowing for performance optimizations.