27rohitb.github.io

Datatypes

Pre-defined datatypes:

Arrays

Array is the most general purpose container similar to list in python. 1D arrays is vector, 2D array is matrix. Everything else about array is here.

Tuple

Note: Immutable; CAN’t be modified.

t = (1,2,3)

# access
t[1] 

Name Tuple

nt = (a=1, b=2, c="hello")

# access
nt[1]
nt.a    # access using keys

Dictionary

dik = Dict('a' => 1, 'b'=>2)

Note:

Constants:

Some constants that dont exist or we know better : P

const pie=3.1415

User defined:

Struct:

Everything about struct is here

Abstract type ( Parametric ):

Its basically an alternative to Abstract classes BUT it is for structs. Its also an example of parametric, since its not a parameter to the function, but it can allow the user to define the datatype on the fly. Similar to templates in C++.

Example:

abstract type Shape{T} end

struct Rectangle{T1, T2} <: Shape{T1}
    len::T1
    wid:T2
end

Usage Example:

r = Rectangle{Float64, Float64}(5.0,4.0)