Intermediate Julia
Anthony Markham
Quantitative Developer
function my_function(param1, param2)
return param1, param2
end
my_function(1, 2)
(1, 2)
The function arguments that we have seen so far are positional.
Positional arguments rely on the order that they are specified in.
function my_function(param1, param2)
return param1, param2
end
my_function(2, 1)
(2, 1)
function my_function(param1, param2=2)
return param1, param2
end
my_function(1)
(1, 2)
Type declarations allow us to control the type of data passed into a function.
Allows us to safeguard our code against incorrect values passed to functions.
Each parameter can have a data type specified. Use double colon ::
syntax.
function my_function(param1::String, param2::Integer=2)
return param1, param2
end
my_function(1)
MethodError: no method matching my_function(::Int64)
Intermediate Julia