In Julia you
can provide default values to the arguments in function.
For example,
julia> function power(base=2,power=2) base^power end power (generic function with 3 methods) julia> power() 4 julia> power(5) 25 julia> power(5, 3) 125
function power(base=2,power=2)
If you call
power function like power(), then it takes base=2 and power=2.
If you call
power function like power(10), then it calculates 10^2
If you call power function like power(10,3), then it calculates 10^3.
If you call power function like power(10,3), then it calculates 10^3.
No comments:
Post a Comment