Introduction to Julia
James Fulton
Climate informatics researcher
# Strings are surrounded by " " name = "Jane" # Cannot use 'Jane'# Strings can be any length book = "It is a truth universally acknowledged, ..."println(name)println(book)
JaneIt is a truth universally acknowledged, ...
# Triple quotes poem = """Beware the Jabberwock, my son! The jaws that bite, the claws that catch!"""println(poem)
Beware the Jabberwock, my son!
The jaws that bite, the claws that catch!
greeting = """ " Well hello there " """
println(greeting)
" Well hello there "
greeting = " " Well hello there " "
ERROR: syntax: ...
name = "James" greeting = "Well hello there, "# Concatenate two stringsprintln(greeting*name)
Well hello there, James
name = "James"# Interpolate with $ symbol greeting = "Well hello there, $name"println(greeting)
Well hello there, James
x_int = 10# Insert integer into string println("The value is $x_int")
The value is 10
x_float = 1.0# Insert float into string println("The value is $x_float")
The value is 1.0
x_bool = true# Insert boolean into string println("The value is $x_bool")
The value is true
x_char = 'A'# Insert character into string println("The value is $x_char")
The value is A
x = 10 y = 3# Insert x*y into string println("The product of x and y is $(x*y)")
The product of x and y is 30
x = 10 y = 3# Insert x*y into string println("The product of x and y is \$(x*y)")
The product of x and y is $(x*y)
# Customer's seat seat = "E5"# Select character row = seat[1] # this returns 'E'println(row)println(typeof(row))
EChar
# Customer's seat seat = "E5" # Select characters row = seat[1] # this returns 'E' number = seat[2] # this returns '5'println("Your seat is in row $row, seat number $number.")
Your seat is in row E, seat number 5.
# Customer's seat
seat = "E5"
# Select characters
row = seat[1] # this returns 'E'
number = seat[end] # this returns '5'
println("Your seat is in row $row, seat number $number.")
Your seat is in row E, seat number 5.
# Customer's seat
seat = "E5"
# Select characters
row = seat[end-1] # this returns 'E'
number = seat[end] # this returns '5'
println("Your seat is in row $row, seat number $number.")
Your seat is in row E, seat number 5.
receipt = "08:30 - coffee - \$3.50" println(receipt)
08:30 - coffee - $3.50
# Index position: # 12345... receipt = "08:30 - coffee - \$3.50"time = receipt[1:5] # Select first 5 charactersprintln(time)
08:30
# Index position from end: # 4321end receipt = "08:30 - coffee - \$3.50" time = receipt[1:5] # Select first 5 charactersprice = receipt[end-4:end] # Select last 5 charactersprintln(time)println(price)
08:30$3.50
Introduction to Julia