IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

Mojo language reference

The Mojo language reference provides a concise guide for Mojo's syntax, organized by grammar construct and designed for quick lookup when you need the exact rules or form of a language element.

Mojo cheat sheets

Quick reference cards for Mojo's syntax and keywords

Identifiers and keywords

Naming rules, reserved words, escaped identifiers, and argument conventions

Literals

Integer, floating-point, string, t-string, boolean, None, and Self literals

Numeric types

`SIMD`, `DType`, `Scalar`, `Int`, integers, floating-point, `Byte`, and conversions

Operators

Operator precedence, associativity, and implementing operators for custom types

Expressions

Tuples, collection displays, member access, calls, subscripts, ternary conditionals, and comprehensions

Simple statements

Imports, assignments, return, raise, break, continue, and compile-time declarations

Compound statements

`if` statements, loops, error handling with `try`/`except`, context managers, and compile-time control flow

Function declarations

Signatures, parameters, arguments, default values, constraints, effects, and special methods

Struct declarations

Fields, methods, initializers, destructors, and trait conformance for structs

Trait declarations

Required and provided methods, associated types, trait inheritance, trait composition, and conformance

Closure declarations

Capture lists, capture conventions, move capture, parametric closures, and effects

Lambda expressions

Anonymous single-expression functions, elided capture lists, and thin function values

Inline MLIR

Built-ins for calling MLIR operations the language doesn't expose natively

Docstrings

Sections, placement, formatting, code examples, and compiler checks

Decorators

Modify or extend the behavior of structs, functions, and other declarations at compile time