In [1]:
function sum(a)
s = 0.0
for x in a
s += x
end
return s
end
sum([1, 2, 3])
Out[1]:
In [2]:
1 + 2 + 3
Out[2]:
In [9]:
?println
Out[9]:
In [10]:
print("hello world!")
In [11]:
28 + 58
Out[11]:
In [5]:
;ls
In [6]:
;ls -la
In [7]:
println("I'm excited to learn Julia!")
In [8]:
my_answer = 42
typeof(my_answer)
Out[8]:
In [12]:
asdf = "some string"
typeof(asdf)
Out[12]:
In [13]:
jkl = 0.45
typeof(jkl)
Out[13]:
In [14]:
# \:smi + <tab> --> select wtih down arrow + <enter> --> <tab> + <enter>
😺 = 1
typeof(😺)
Out[14]:
In [15]:
#=
multiline comments
another line
=#
a = 4
Out[15]:
In [16]:
100 % 3
Out[16]:
In [17]:
10^2
Out[17]:
In [18]:
?convert
Out[18]:
In [19]:
convert(Float32, 4)
Out[19]:
In [20]:
s1 = "I am a string."
Out[20]:
In [21]:
s2 = """I am also a
a string."""
Out[21]:
In [22]:
typeof('a')
Out[22]:
In [23]:
"""Hooray! No "errors" anymore!"""
Out[23]:
In [24]:
name = "Curtis"
toes = 10
fingers = 10
println("Hello, my name is $name and I have $fingers fingers and $toes toes and, of course, $(fingers + toes) digits.")
In [25]:
s5 = string("a", "b")
Out[25]:
In [26]:
s4 = "yes"
s5 = "no"
s4*s5
Out[26]:
In [27]:
s4 ^ 3
Out[27]:
In [28]:
(1,2)
Out[28]:
In [29]:
myanimals = ("dog", "cat")
Out[29]:
In [30]:
typeof(myanimals)
Out[30]:
In [31]:
myanimals[1]
Out[31]:
In [32]:
myanimals[1] = "hamster"
In [33]:
mypets = (dog = "london", otherdog = "belle")
Out[33]:
In [34]:
mypets.dog
Out[34]:
In [35]:
mypets[1]
Out[35]:
In [36]:
myphonebook = Dict("Curtis" => "817-372-6396", "Amanda" => "817-773-1966")
Out[36]:
In [37]:
myphonebook["Curtis"]
Out[37]:
In [38]:
myphonebook["Curtis work"] = "817-302-7885"
Out[38]:
In [39]:
myphonebook
Out[39]:
In [40]:
pop!(myphonebook, "Curtis work")
Out[40]:
In [41]:
myphonebook
Out[41]:
In [42]:
mypets = ["belle", "london"]
Out[42]:
In [43]:
myanimals[1]
Out[43]:
In [44]:
myanimals[3]
In [45]:
mypets[3] = "abigail"
In [ ]:
In [46]:
push!(mypets, "abigail")
Out[46]:
In [47]:
mymixture = [1, 2, "test", (1,2)]
Out[47]:
In [48]:
push!(mymixture, "100")
Out[48]:
In [49]:
pop!(mymixture)
Out[49]:
In [50]:
some2darray = [[1, 2, 3], [4, 5, 6]]
Out[50]:
In [51]:
myanimals
Out[51]:
In [52]:
rand(4, 3)
Out[52]:
In [53]:
rand(4, 2, 3)
Out[53]:
In [54]:
mymixture
Out[54]:
In [55]:
mymixture2 = mymixture
Out[55]:
In [56]:
pop!(mymixture)
Out[56]:
In [57]:
mymixture2
Out[57]:
In [58]:
mymixture3 = copy(mymixture)
Out[58]:
In [61]:
push!(mymixture3, "yes")
Out[61]:
In [62]:
mymixture
Out[62]:
In [63]:
y = Dict{Any, Any}
Out[63]:
In [64]:
y[1] = "yes"
In [65]:
y["ah"] = 1
In [66]:
y
Out[66]:
In [67]:
y["ah"] = "1"
In [68]:
somedict = Dict{Any, Any}
Out[68]:
In [70]:
somedict["a"] = "a"
In [71]:
length(somedict)
In [72]:
typeof(somedict)
Out[72]:
In [73]:
somedict = Dict{Any, Any}()
Out[73]:
In [74]:
somedict["a"] = 1
Out[74]:
In [75]:
somedict
Out[75]:
In [1]:
n = 0
while n < 10
println("n = $n")
n += 1
end
In [4]:
for n in 1:2:10
println("n = $n")
end
In [5]:
myfriends = ["Amanda", "Alene", "London", "Belle"]
Out[5]:
In [10]:
for f in myfriends
println("Hello, $(f)!")
end
In [14]:
m, n = 5, 5
A = fill(0, (m, n))
Out[14]:
In [12]:
for i in 1:m
for j in 1:n
A[i, j] = i + j
end
end
In [13]:
A
Out[13]:
In [20]:
for i in 1:m, j in 1:n
A[i, j] = i + j
end
A
Out[20]:
In [22]:
C = fill(0, (m, n))
Out[22]:
In [23]:
C = [i + j for i in 1:m, j in 1:n]
Out[23]:
In [25]:
a = ["hello my $f" for f in myfriends]
Out[25]:
In [ ]: