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, andBoolare the everyday scalars.Stringowns text.StringSliceborrows it.List,Dict,Set, andOptionalcover the usual collections.SIMDandDTypeare how numeric kernels talk about vectors and scalar kinds.- A literal such as
1.5keeps 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.