November 2017
Beginner
316 pages
6h 40m
English
A function argument is a variable passed to a function in the form of an input so that it returns a specific output. A very simple example of a function taking an argument is stated as follows:
julia> function say_hello(name) println("hello $name") endsay_hello (generic function with 1 method)julia> say_hello("rahul")hello rahul
Here, the say_hello function takes an argument called name, which is a string. Upon calling the function with the name rahul, the hello string becomes hello rahul. Simple!
One thing to keep in mind is that, although Julia is dynamically typed, it supports the use of statically-typed variables. Modifying the preceding code, we have:
julia> function say_hello(name::String) println("hello $name") endsay_hello ...Read now
Unlock full access