Mojo Tutorial
This is a practical guide to Mojo for people who are new to it. The lessons are short, every example is real code, and I’ll be honest about the parts that usually give beginners trouble.
Your first Mojo program
Section titled “Your first Mojo program”Here’s a full Mojo program. Save it as hello.mojo and run it with mojo hello.mojo:
def main(): print("Hello, World!")Output:
Hello, World!If you know Python, that should look very familiar. Mojo borrows Python’s syntax on purpose, so indentation matters and print works the way you’d expect. The difference is that Mojo needs a main function as the starting point, and it compiles your code instead of interpreting it.
Why Mojo?
Section titled “Why Mojo?”Mojo is a language from Modular, built for fast code on CPUs and GPUs, especially for AI work. The idea is to write something that reads like Python but runs closer to the speed of C++ or Rust. You get types, structs and control over memory when you want them, and you can still call Python libraries from Mojo.
One honest heads-up: Mojo reached 1.0 in August 2026 and is still changing between releases. Syntax from a year-old example might not compile today, so check which version a tutorial was written for. This one is written for Mojo 1.2. It also runs on Linux and macOS; on Windows you’ll need WSL.
What’s inside
Section titled “What’s inside”The lessons are in the sidebar on the left, in the order we suggest. Every example was run on Mojo 1.2, and every lesson ends with practice exercises and a short quiz.
| Section | What you’ll learn | Start here |
|---|---|---|
| Getting Started | What Mojo is, installing it, your first programs, print and formatting |
Mojo Intro |
| Basics | Variables, numbers, strings, booleans, operators, conversions | Mojo Variables |
| Control Flow | if, loops and match |
Mojo If…Else |
| Functions | Functions, arguments, scope, closures and lambdas | Mojo Functions |
| Collections | Lists, dictionaries, sets, tuples, Optional and sorting |
Mojo Lists |
| Structs & Traits | Your own types and how to make them printable and comparable | Mojo Structs |
| Ownership & Memory | The part that’s new for Python developers, one step at a time | Mojo Value Semantics |
| Error Handling | raises, try/except and your own errors |
Mojo Errors |
| Compile Time & Generics | comptime, parameters and code that works for many types |
Mojo Compile-Time Code |
| Performance | SIMD, vectorize, parallelize and measuring honestly |
Mojo SIMD |
| Python & C | Using Python libraries from Mojo, and Mojo from Python and C | Mojo and Python |
| GPU Programming | How GPU code works in Mojo | Mojo GPU Basics |
| Building Real Programs | Modules, files, arguments, input and building apps | Mojo Modules & Packages |
| Compiler Errors | What common error messages mean and how to fix them | Errors Explained |
| Projects | Small programs from start to finish | Guessing Game |
If you’re starting from zero, go in order. If you already know Python, Mojo for Python Developers is a quick way in, and the cheat sheet is handy to keep open.
Quick check
Section titled “Quick check”See if that landed
Official docs worth bookmarking
Section titled “Official docs worth bookmarking”- The Mojo Manual: the official guide
- Install Mojo: the official install page
- Mojo standard library: the day-to-day reference