Introduction to Julia
James Fulton
Climate informatics researcher
# Store run times with many variables
runtime1 = 33.1
runtime2 = 32.7
runtime3 = 34.2
runtime4 = 31.9
# Store runtimes in array
runtimes = [33.1, 32.7, 34.2, 31.9]
[
]
,
in beween values# Store runtimes in array
runtimes = [33.1, 32.7, 34.2, 31.9]
println(typeof(runtimes))
Vector{Float64}
# Store runtimes in array
runtimes = [33.1, 32.7, 34.2, 31.9]
println(typeof(runtimes))
Vector{Float64}
# Store runtimes in array
runtimes = [33.1, 32.7, 34.2, 31.9]
println(eltype(runtimes))
Float64
# Store integers in array
number_of_customers = [11, 19, 31, 27]
println(typeof(number_of_customers))
Vector{Int64}
# Store strings in array
names = ["Amit", "Barbara", "Carlos"]
println(typeof(names))
Vector{String}
# Store characters in array
grades = ['A', 'B', 'B', 'A']
println(typeof(grades))
Vector{Char}
# Store booleans in array
correct_answers = [true, false, true]
println(typeof(correct_answers))
Vector{Bool}
# Store multiple types in array
# string bool int char float
items = ["James", true, 10, 'B', -20.3]
println(typeof(items))
Vector{Any}
# Store array of item names
item_names = ["chalk", "cheese", "eggs", "ham"]
# Store array of item prices
item_prices = [2.30, 3.50, 4.25, 2.00]
println(typeof(item_names))
println(typeof(item_prices))
Vector{String}
Vector{Float64}
# Index: 1 2 3 4
item_names = ["chalk", "cheese", "eggs", "ham"]
# Index: 1 2 3 4
item_prices = [2.30, 3.50, 4.25, 2.00]
println(item_names[1])
println(item_prices[1])
chalk
2.30
# Index: 1 2 3 4
item_names = ["chalk", "cheese", "eggs", "ham"]
# Index: 1 2 3 4
item_prices = [2.30, 3.50, 4.25, 2.00]
println(item_names[end])
println(item_prices[end])
ham
2.00
# Index: 1 2 3 4
item_names = ["chalk", "cheese", "eggs", "ham"]
# Index: 1 2 3 4
item_prices = [2.30, 3.50, 4.25, 2.00]
println(item_names[end-1])
println(item_prices[end-1])
eggs
4.25
# Index: 1 2 3 4
item_names = ["chalk", "cheese", "eggs", "ham"]
# Index: 1 2 3 4
item_prices = [2.30, 3.50, 4.25, 2.00]
println(item_names[1:2])
["chalk", "cheese"]
Introduction to Julia