Skip to content

Mojo Intro

Mojo is a programming language that looks like Python but runs much faster. It was built for code where speed really matters, like AI models, number crunching and programs that run on GPUs.

Mojo comes from Modular, a company started by Chris Lattner (who also created LLVM and Apple’s Swift language). It was first shown in 2023, and its standard library is open source.

Python is easy to read and write, which is why most AI work happens in it. But plain Python is slow. So the fast parts of popular libraries like NumPy and PyTorch are written in C, C++ or CUDA, and you end up working in two languages: Python for the easy parts and something much harder for the fast parts.

Mojo’s idea is to give you one language for both:

  • Python-style syntax, so it’s easy to pick up if you already know Python.
  • Compiled code, so it runs at speeds close to C++ and Rust.
  • Types, structs and control over memory when you want them, and not before.
  • Python interop, so you can still import and use Python libraries.

A rough map of where Mojo sits next to languages you might know:

Language Feels like Speed Runs on GPUs
Python Python Slow Through libraries written in other languages
C++ C++ Fast With CUDA or similar
Rust Rust Fast Possible, but not its main focus
Mojo Python Fast Yes, it’s built for that

The takeaway: Mojo aims to be as easy to read as Python and as fast as C++.

  • AI and machine learning: writing fast building blocks for models
  • GPU programming: Mojo can target GPUs without switching to CUDA
  • Speeding up Python code: rewriting the slow parts of a Python program in Mojo

You don’t need to understand every detail yet:

def main():
var name = "Mojo learner"
print("Hello,", name)

Output:

Hello, Mojo learner

If you know Python, the only new thing here is var, which declares a new variable.

If you know Python, you can write simple Mojo programs on day one. The harder parts come later: types, structs, and how Mojo handles memory. Those are new ideas if you’ve only used Python, but you can learn them one at a time, and this guide is written to help you do that.

  • Mojo is a fast, compiled language with Python-style syntax.
  • It was built for AI and GPU work, where speed matters most.
  • You can add types and low-level control step by step.
  • It can use Python libraries, but most Python code won’t run unchanged.

Next up: installing Mojo and running your first program.

Quick check

1. Which language does Mojo look like?

2. What kind of work was Mojo built for?

3. What does var do in Mojo?

Score: 0 / 3