🎓 A1Learner
🔍
0 of 52 lessons completed

Julia Basic Types

A type is the kind of a value. Every value in Julia has a type, such as a whole number or a piece of text.

typeof names a whole number and a decimal

The first line asks for the type of a whole number. The second line asks for the type of a decimal.

println(typeof(42))
println(typeof(3.5))

Bool and Char are separate types

The variable ready holds a Bool value. The variable letter holds a Char value.

ready = true
letter = 'A'
println(typeof(ready))
println(typeof(letter))

Double quotes make a String and single quotes make a Char

The same letter gives two different types here. The quotes around it decide which type it is.

println(typeof("A"))
println(typeof('A'))

Example

name = "Ana"
age = 31
member = true
println(typeof(name))
println(typeof(age))
println(typeof(member))

Key points

  • Int: the type of a whole number with no decimal part, such as 42.
  • Float: the type of a number with a decimal part, such as 3.5.
  • Bool: the type of a value that is either true or false.
  • Char: the type of one character, written in single quotes, such as 'A'.
  • String: the type of text, written in double quotes, such as "Ana".
  • Use typeof to find the type of a value.

In this example, name holds text, age holds a whole number, and member holds a Bool value. The three typeof lines print String, Int64, and Bool, one type for each variable.

Note

typeof prints Int64 for a whole number and Float64 for a decimal on this system.

Try it Yourself

Edit the code, then press Run.

Running is simulated · JuliaHub

Exercise

What does typeof("Hi") print?