Version: 1.1.0

Types

Mojo ships a small set of standard types and expects libraries to add more as structs. Numbers, strings, collections, and optional values cover most programs.

Essentials

  • Int, UInt, Float64, and Bool are the everyday scalars.
  • String owns text. StringSlice borrows it.
  • List, Dict, Set, and Optional cover the usual collections.
  • SIMD and DType are how numeric kernels talk about vectors and scalar kinds.
  • A literal such as 1.5 keeps extra precision until it is stored in a concrete type.

Example

def main():
    var name: String = "mojo"
    var flags = List[Int](1, 2, 4)
    var maybe: Optional[String] = None
    print(name, flags[0], maybe)

Keep in mind

Reach for a standard type first. Define a struct only when a value needs its own fields or invariants.