三元运算符的格式: a ? b : c a 是条件表达式,如果条件 a 为真,就执行 b:如果条件 a 为假,就执行 c 二选一 julia> println(1 < 2 ? "1 is smaller than 2" : "1 is bigger than 2") 1 is smaller than 2 julia> println(1 > 2 ? "1 is smaller than 2" : "1 is b…
return 返回值 要返回函数最后一个表达式的值,可以省略 return julia> function f(x, y) x + y end f (generic function with 1 method) julia> function g(x, y) return x + y end g (generic function with 1 method) julia> f(2, 3) 5 julia> g(2, 3) 5 有没有 return 结果是一样的,return 可…
Julia 中的函数是将一系列参数组成的元组映设到一个返回值的对象 Julia 中定义函数的基本语法为: julia> function f(x, y) x + y end f (generic function with 1 method) 该函数等价的赋值形式 f(x, y) = x + y 调用该函数 julia> function f(x, y) x + y end f (generic function with 1 method) julia> f(2, 3) 5 f 指向的…