isa(1, Int)
#> true
isa(1, Int64)
#> true
isa(1, Int128)
#> false2 Type
2.1 Check type by isa
or
1 isa Int
#> true2.2 User-defined Type
let’s create a struct to represent scientific open source programming languages.
struct Language
name::String
title::String
year_of_birth::Int64
fast::Bool
endAccess field names
fieldnames(Language)
#> (:name, :title, :year_of_birth, :fast)2.2.1 Initiate objects (immutable)
julia = Language("Julia", "Rapidus", 2012, true)
#> Language("Julia", "Rapidus", 2012, true)
R = Language("R", "R & R", 1993, false)
#> Language("R", "R & R", 1993, false)typeof(julia)
#> Language2.2.2 Accessing individual values
julia.name
#> "Julia"
R.name
#> "R"2.2.3 Printing with Base.show method
"Hello World"
#> "Hello World"
Base.show("Hello World")
#> "Hello World"Implement using print()
print("Hello World")
#> Hello Worldusing Datesfunction Base.show(io::IO, l::Language)
years_old = year(today()) - l.year_of_birth
print(io, "$(l.name) is $years_old years old,")
print(io, " created by $(l.title).")
return nothing
endjulia
#> Julia is 10 years old, created by Rapidus.R
#> R is 29 years old, created by R & R.