1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/julia_course.git synced 2024-11-16 13:28:10 +00:00

Add more comments

This commit is contained in:
Mo8it 2022-03-26 01:02:29 +01:00
parent 6b9d16d857
commit b8cb7cbe30

View file

@ -68,27 +68,33 @@ md"""
5 / 2
# ╔═╡ 02282f61-e1ca-483d-b6de-feeccedd7bc0
# Remainder of division
5 % 2
# ╔═╡ e4237ccd-b042-408b-8177-4c0d31a28caa
# Quotient of division
5 ÷ 2
# ╔═╡ d1bf37f9-5135-48b8-8f9b-84ddd4a86157
md"""
## Variables
Variables store data 📦️
"""
# ╔═╡ 8d005ddd-0308-4a06-8bae-251387facf6f
# Assignment
a = 2
# ╔═╡ b7d27cd4-a655-492e-b2b3-cdc745b2c2da
b = 3
# ╔═╡ 141950e5-e9f8-414b-b08d-86777428cbec
# Change a or b above and see what happens
# Change a or b above and see what happens 🪄
a * b
# ╔═╡ 2e7f29ce-3afa-4c12-838d-8051c0567e20
# You can also store the result of a computation
c = a + b
# ╔═╡ 2121b949-06e7-4079-a25a-d0518ee2ba50
@ -99,42 +105,80 @@ md"""
- `Float16`, `Float32`, **`Float64`**
- `Int8`, `Int16`, `Int32`, **`Int64`**, `Int128`
- `UInt8`, `UInt16`, `UInt32`, `UInt64`, `UInt128`
All other types (like strings) are composed.
Spoiler: You can compose your own types! More about this later 😉
"""
# ╔═╡ 534f3b32-1fc9-4eed-887a-2cac66c2bdb4
# Bool
bo = true
# ╔═╡ f20de3db-f270-4c43-aab7-692c313b5fa9
# Char
# Single quotes!
ch = 'c'
# ╔═╡ c72f187f-9626-45d9-870a-267c8530202c
# String, not a char!
# Double quotes!
st1 = "c"
# ╔═╡ e4295349-fc5c-48cb-975e-803e44d1a06e
# Shows the type of a variable
typeof(ch)
# ╔═╡ 7287122b-e5ea-4f69-963b-023483914992
typeof(st1)
# ╔═╡ 8b6609b0-5d6d-4c7d-a144-deaff79f93e9
# A string is a chain of characters
hello = "Hello world!"
# ╔═╡ 196682db-f5e1-4c07-9d35-644da3eecdd6
md"""
Pluto notebooks automatically print the output of the cell.
When using scripts instead of notebooks, `println` is needed.
"""
# ╔═╡ 10fdb32f-b66f-4c4e-abd9-e856549941b8
# Print to the console
# ln stands for new line which is printed at the end of the output
println(hello)
# ╔═╡ 00ba151b-a741-448d-b8bf-775217250915
# Float
fl = 42.0
# ╔═╡ 204cf77f-bf37-4110-9c9f-1f9236301ba9
# Float64 is the default
typeof(fl)
# ╔═╡ 750bba32-e695-48f1-af70-70c94d13366b
# Integer
meaning_of_life = 42
# ╔═╡ 0b663bcb-4ff4-4597-b28b-b58c9cbfa181
# Int64 is the default
typeof(meaning_of_life)
# ╔═╡ 608d4433-6e68-4f95-8581-437234b58e87
md"""
## Converting
## Convertion
"""
# ╔═╡ beadbfd3-0015-449a-b6e7-b5182b396c1d
# Converting a float to an integer
convert(Int64, 3.0)
# ╔═╡ 552fafa4-fad5-4efe-895f-255b3ec5c858
# Complex is a composed type for complex numbers
convert(Complex, 3.0)
# ╔═╡ d11fde7f-3238-4013-bd2d-546aab0d9f9c
# This does not work!
# This does not work! See rounding below.
# convert(Int64, 3.2)
# ╔═╡ 036a2c43-dbc9-487c-96aa-94324eeb4a52
@ -143,10 +187,11 @@ md"""
"""
# ╔═╡ 1e954726-254e-41bb-a62f-17bdc9884bee
# We have to tell Julia explicitely what to do
# We have to tell Julia explicitely what to do when converting a float with non zero digits after the decimal point.
round(Int64, 3.2)
# ╔═╡ d74f6c46-f5a8-4720-bcaf-936f1508efda
# The default is rounding to 0 digits after the decimal points, but keeping the float type.
round(π)
# ╔═╡ 3e5daca6-5aa8-42bf-988b-c09fb17388df
@ -185,6 +230,7 @@ md"""
"""
# ╔═╡ 0596fe87-4201-476e-8e11-618c621c5474
# Concatenation
# ⚠️ Not +
"Hello " * "world!"
@ -192,21 +238,28 @@ md"""
new_to_julia = "Hi, I am new to Julia!"
# ╔═╡ da5fb1f9-2a2d-4148-8ba5-8c4a529829e9
# check if a string is part of another one
# ⚠️ Not in
contains(new_to_julia, "Hi")
# ╔═╡ 943da836-384d-4774-aaf4-54c27feb53d8
# Split on occurrences of the provided delimeneter (comma here)
split(new_to_julia, ",")
# ╔═╡ a96f3ae9-12df-4df8-85da-09b9b1e47de1
join(["Hello", "brave", "new", "world", "!"], " ", "")
# Join a list of strings with a provided delimeter and last delimeter
# Some of the used arguments are optional, see the docs 📚️
# Lists are actually called vectors in Julia. More about this later!
join(["Apple", "Banana", "Orange", "Lemon"], ", ", " and ")
# ╔═╡ 8d106ad2-5f92-4138-bfff-56ee21e098fa
# Multi line strings with three double quotes
multi_line_string = """Line 1
Line 2
Line 3"""
# ╔═╡ f8bc4051-93c6-4376-abaa-7b4cb4b8f607
# To see the new lines (\n)
println(multi_line_string)
# ╔═╡ b25dc5f2-e186-4da1-b045-47b22c93799b
@ -224,9 +277,11 @@ b
a_mult_b = a * b
# ╔═╡ d2607457-1794-4a0f-af41-cb80aadb598f
# Use $ followed by the name of a variable to insert the variable into a string
"The result of $a * $b is $a_mult_b"
# ╔═╡ 23dbbe13-d997-4f9f-a300-7cb78c4fb8ee
# Use brackets after $ to insert a result of computation instead of a variable
"The result of $a * $b is $(a * b)"
# ╔═╡ e767971a-7e1d-4a78-88d7-03e4ae4d51db
@ -236,7 +291,7 @@ a_mult_b = a * b
# ╔═╡ 9e3f698d-e57b-46c2-98e0-157fa7b06ae6
md"""
## Arrays
An array is a **mutable** **ordered** collection of elements.
An array is a **mutable ordered** collection of elements of the same type.
Arrays can have one dimension (vector), two dimensions (matrix) or more (tensor).
"""
@ -662,10 +717,15 @@ uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
# ╠═534f3b32-1fc9-4eed-887a-2cac66c2bdb4
# ╠═f20de3db-f270-4c43-aab7-692c313b5fa9
# ╠═c72f187f-9626-45d9-870a-267c8530202c
# ╠═e4295349-fc5c-48cb-975e-803e44d1a06e
# ╠═7287122b-e5ea-4f69-963b-023483914992
# ╠═8b6609b0-5d6d-4c7d-a144-deaff79f93e9
# ╟─196682db-f5e1-4c07-9d35-644da3eecdd6
# ╠═10fdb32f-b66f-4c4e-abd9-e856549941b8
# ╠═00ba151b-a741-448d-b8bf-775217250915
# ╠═204cf77f-bf37-4110-9c9f-1f9236301ba9
# ╠═750bba32-e695-48f1-af70-70c94d13366b
# ╠═0b663bcb-4ff4-4597-b28b-b58c9cbfa181
# ╟─608d4433-6e68-4f95-8581-437234b58e87
# ╠═beadbfd3-0015-449a-b6e7-b5182b396c1d
# ╠═552fafa4-fad5-4efe-895f-255b3ec5c858
@ -695,7 +755,7 @@ uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
# ╠═d2607457-1794-4a0f-af41-cb80aadb598f
# ╠═23dbbe13-d997-4f9f-a300-7cb78c4fb8ee
# ╠═e767971a-7e1d-4a78-88d7-03e4ae4d51db
# ╠═9e3f698d-e57b-46c2-98e0-157fa7b06ae6
# ╟─9e3f698d-e57b-46c2-98e0-157fa7b06ae6
# ╟─d1680205-a8eb-4ef6-ae4f-059e7a30f5c1
# ╠═b54ace0e-8947-46a3-842a-05b5cbfc4e87
# ╠═8c47710f-1ed2-40fd-9290-374b498380e3
@ -715,7 +775,7 @@ uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
# ╠═65d3ddc2-36ed-4126-9211-e838ffc0d859
# ╠═641e8c05-3e80-47e5-be77-91090a5f799a
# ╠═2b9a5867-ca82-4a27-a700-bd0bd6c89bbe
# ╠═87b43f26-7437-4ee9-9b83-5b21e86dd0c9
# ╟─87b43f26-7437-4ee9-9b83-5b21e86dd0c9
# ╠═22f5ebc1-fd5c-4ee7-b169-8144fbd9b570
# ╠═7479c420-2e04-4fe7-823c-3fde9efb54ca
# ╠═4cd82256-be63-4db1-b2af-82a1358f4881