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 is young and still changing quickly. Syntax from a year-old example might not compile today, so check which version a tutorial was written for. It also runs on Linux and macOS; on Windows you’ll need WSL.
How to use this guide
Section titled “How to use this guide”Lessons will appear on the left as they’re written. Work through them roughly in order if you’re starting from zero.
Quick check
Section titled “Quick check”See if that landed
1. Which language does Mojo borrow its syntax from?
2. Where does a Mojo program start?
3. How do you run Mojo on Windows?
Score: 0 / 3
Official docs worth bookmarking
Section titled “Official docs worth bookmarking”- Mojo manual: the official guide
- Get started with Mojo: installing it and your first project
- Mojo standard library: the day-to-day reference