Skip to content

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.

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.

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.

Lessons will appear on the left as they’re written. Work through them roughly in order if you’re starting from zero.

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