int = 4 # An integer str = "Hi" # A string float = 1.2 # A floating-point number bool = true # A boolean (also false) typeof(int) typeof(str) typeof(float) x = UInt8(1) # 8-bit wide unsigned integer y = Int32(-1) # 32-bit wide signed integer z = Float32(0.2) # single precision α = Float16(-1.0) # half precision β = ComplexF64(2. + 8im) # Complex number (composed of two Float64) println(typeof(1 + 1.2)) println(typeof(x * y)) # x was Uint8, y was Int32 x = Float32(1.) 4x # No "*" needed println(5 % 2) 5^6 2.3^6 println(4 - Float32(2)) println(8 / 3) # Note conversion to Float64 typeof(8 / 3) x = 6 // 3 println(typeof(x), " ", Int(x)) √2 # == sqrt(2) "Concatenating " * "strings is done " * "using multiplication" Int(2.0) x = Float32(1.0) Float64(x) Int(2.3) UInt8(-1) Float64(2.0 + 1im) string(1.2) ceil(Int, 2.3) round(Int32, 4.5) x = 1.2 println("x is currently $x.") println("two less is $(x - 2)") # arbitrary precision b = big"12"; println(b, " is a ", typeof(b)) f = big"-1.2"; println(f, " is a ", typeof(f)) # Or wir an explicit cast: b = BigInt(12) f = BigFloat(-1.2) # Note the difference to the above result x = 15 println(x) x = "abc"; # x newly assigned, memory by the "15" will be freed at some point in the future x = 3; y = 5 if x < y println("x is less than y") elseif x > y println("x is greater than y") else println("x is equal to y") end x = 5 while x > 3 println("Now x is $x") x -= 1 end for i in 1:5 println("Hello from number $i") end accu = 0 for j ∈ 1:0.5:3 # Note the step parameter accu += j end println(accu) true || println("The RHS of || is only run") false || println("if the LHS is false") iseven(3) && println("The RHS of || is only run") isodd(3) && println("if the LHS is true") x = 3 x < 5 ? "smaller than 5" : "larger or equal 5" z = begin x = 5 y = -3 x + y end # Or equivalently z = (x = 5; y = -3; x + y) d = randn(4) using LinearAlgebra import Pkg; Pkg.add("LinearAlgebra") using LinearAlgebra Diagonal(d)