Apply Now Apply Now Apply Now
header_logo
Post thumbnail
PROGRAMMING LANGUAGES

Getting Started with Modular’s Mojo Programming Language

By Lukesh S

If you have been working with Python for AI or machine learning, you already know the trade-off: Python is easy to write, but it can be painfully slow when performance really matters. That is exactly the gap Modular set out to close with Mojo.

Mojo is not just another programming language. It is designed from the ground up for AI development, borrowing Python’s readable syntax while delivering performance that rivals C++ and Rust. For developers who work on model training, inference pipelines, or hardware-level AI systems, that combination is significant.

In this guide, you will get a complete introduction to Mojo. You will understand why it was built, how it works, and how to start writing code in it, even if your background is primarily in Python.

TL;DR Summary

  1. Mojo is a new programming language by Modular, designed to combine Python’s simplicity with the performance of systems languages like C++ and Rust.
  2. It is built specifically for AI and machine learning workloads, making it significantly faster than standard Python in compute-heavy tasks.
  3. This guide walks you through what Mojo is, how it differs from Python, how to set up your environment, and how to write your first Mojo program.
  4. You will also learn about Mojo’s key features, including its type system, fn vs def functions, SIMD support, and memory management model.
  5. By the end, you will have a solid foundation to start exploring Mojo for AI development, systems programming, or high-performance computing projects.

Table of contents


  1. What is Mojo?
  2. Why Was Mojo Created?
  3. Setting Up Your Mojo Environment
    • Option 1: Use the Mojo Playground (Easiest)
    • Option 2: Install Mojo Locally
    • Setting Up VS Code for Mojo
  4. Writing Your First Mojo Program
  5. Core Features of Mojo You Should Know
    • Static Typing
    • SIMD Support
    • Structs
  6. Working With Functions in Mojo
    • def: The Python-Compatible Way
    • fn: The Performance-Oriented Way
  7. Understanding Mojo's Type System
    • Primitive Types in Mojo
    • Type Inference
  8. Memory Management in Mojo
    • Ownership and Borrowing
  9. Where Can You Use Mojo?
  10. Conclusion
  11. FAQs
    • What is the Mojo programming language? 
    • Who created Mojo?
    • Is Mojo the same as Python? 
    • How much faster is Mojo than Python? 
    • Do I need to know Python to learn Mojo? 

What is Mojo?

Mojo is a programming language developed by Modular, the company founded by Chris Lattner, the original creator of Swift and a key contributor to LLVM and Clang.

It is designed to be a superset of Python, which means valid Python code is also valid Mojo code in most cases. But Mojo adds features that Python simply cannot offer, things like static typing, manual memory control, and low-level hardware access.

The goal is straightforward: give AI and ML developers a language that feels familiar but performs at a level that Python never could.

Think of Mojo as Python that has been rebuilt with a systems programming foundation underneath it.

Why Was Mojo Created?

To understand why Mojo exists, it helps to understand the problem it is solving.

Python is the dominant language in AI and data science, but its performance ceiling is a real limitation. Most production AI systems deal with this by writing performance-critical code in C++ or CUDA and wrapping it with Python. It works, but it creates a fragmented development experience; you are essentially maintaining two codebases in two very different languages.

Mojo was created to eliminate that split.

With Mojo, you can write everything, from high-level data processing logic to low-level hardware kernels, in a single language. That is a meaningful shift for teams building large-scale AI systems.

There are a few reasons why this matters right now:

  • AI hardware (GPUs, TPUs, accelerators) is evolving rapidly, and existing tools struggle to keep up
  • Python’s Global Interpreter Lock (GIL) limits true parallelism
  • Writing CUDA or C++ extensions for Python is time-consuming and error-prone
  • The AI industry needs a language that can grow with hardware complexity

Mojo addresses all of these directly.

Setting Up Your Mojo Environment

Getting Mojo running on your machine is straightforward. Here is how to do it step by step.

Option 1: Use the Mojo Playground (Easiest)

If you want to try Mojo without installing anything locally, Modular offers a browser-based playground. Head to developer.modular.com and sign up for access. This is the fastest way to get started and is ideal if you just want to explore the syntax.

Option 2: Install Mojo Locally

For local development, you will need to install the Modular CLI first.

Step 1: Install the Modular CLI:

curl https://get.modular.com | sh -

Step 2: Authenticate your account:

modular auth

This will prompt you to log in with your Modular account. Create one at developer.modular.com if you have not already.

Step 3: Install Mojo:

modular install mojo

Step 4: Verify the installation:

mojo --version

If you see a version number printed, you are ready to go.

MDN

Setting Up VS Code for Mojo

Modular offers an official Mojo extension for Visual Studio Code. Search for “Mojo” in the VS Code extensions marketplace and install the one published by Modular. It gives you syntax highlighting, code completion, and inline error checking as you write.

Writing Your First Mojo Program

Once your environment is set up, create a new file with a .mojo extension.

fn main():

    print("Hello from Mojo!")

Run it from your terminal:

mojo hello.mojo

You should see:

Hello from Mojo!

That is your first Mojo program. Notice how similar it looks to Python, the structure is intentionally familiar. The key difference is the use of fn instead of def, which we will cover in detail shortly.

Core Features of Mojo You Should Know

Mojo introduces several features that Python does not have. These are not optional extras, they are central to how Mojo achieves its performance. Here is what you need to understand early on.

Static Typing

In Python, you can assign any value to any variable at any time. Mojo lets you declare variable types explicitly, which helps the compiler optimise your code.

let name: String = "Mojo"

let version: Int = 1

Using let declares an immutable variable — one that cannot be reassigned after initialisation. For mutable variables, use var:

var counter: Int = 0

counter = counter + 1

This distinction matters. Immutability allows the compiler to make stronger guarantees about your code’s behaviour, which translates into better optimisations.

SIMD Support

SIMD stands for Single Instruction, Multiple Data. It is a hardware feature that lets you perform the same operation on multiple data points simultaneously — critical for numerical computing and AI workloads.

Mojo exposes SIMD directly in the language:

from DType import float32

let vec = SIMD[float32, 4](1.0, 2.0, 3.0, 4.0)

This kind of low-level hardware access is something Python simply cannot offer without external libraries written in C.

Structs

Mojo introduces structs, which are similar to Python classes but are resolved at compile time rather than runtime. This makes them significantly faster for performance-critical use cases.

struct Point:

    var x: Float32

    var y: Float32

    fn __init__(inout self, x: Float32, y: Float32):

        self.x = x

        self.y = y

Structs in Mojo are value types by default, they are copied, not referenced, which eliminates a common class of bugs in concurrent code.

If you want to read more about Python and how it helps ease the process of development, then read HCL GUVI’s Free Python Ebook: A Beginner’s Guide to Coding & Beyond, where you can explore Python Libraries and advanced concepts easily!

Working With Functions in Mojo

One of the first things you will notice in Mojo is that there are two ways to define a function: def and fn. Understanding the difference between them is important.

def: The Python-Compatible Way

def in Mojo works similarly to Python. It is flexible, allows dynamic typing, and is familiar to anyone coming from a Python background.

def greet(name):

    print("Hello, " + name)

Use def when you are writing quick scripts, prototyping, or when Python compatibility matters.

fn: The Performance-Oriented Way

fn is Mojo’s stricter function definition. It requires explicit type annotations and enforces stronger rules about variable ownership and mutability.

fn add(a: Int, b: Int) -> Int:

    return a + b

fn functions are what Mojo uses to unlock compiler optimisations. When you annotate types precisely, the compiler knows exactly what to expect and can generate highly efficient machine code.

As a general rule, use def for flexibility, use fn for performance.

Understanding Mojo’s Type System

Mojo’s type system is one of its most important features, and it is worth spending some time here.

Unlike Python, which is dynamically typed, Mojo supports both dynamic and static typing. You can write Python-style dynamic code when you need flexibility, and switch to static typing when performance is the priority.

Primitive Types in Mojo

Here are the core types you will work with most often:

  • Int: Integer values
  • Float32 / Float64: Floating point numbers
  • Bool: True or False
  • String: Text data
  • SIMD: Vectorised numerical data

Type Inference

You do not always have to declare the type explicitly. Mojo can often infer it:

let score = 95  # Mojo infers this as Int

But for performance-critical code, explicit annotation is always the better choice. It removes ambiguity and gives the compiler everything it needs to optimise aggressively.

Memory Management in Mojo

This is an area where Mojo is genuinely different from Python, and it is important to understand it, even at a basic level.

Python manages memory automatically using a garbage collector. You create objects, and Python figures out when to clean them up. This is convenient but comes with unpredictable performance overhead.

Mojo takes a different approach, borrowing concepts from Rust’s ownership model.

Ownership and Borrowing

Every value in Mojo has an owner. When you pass a value to a function, you are either:

  • Lending it (the function reads but does not modify it)
  • Mutating it (the function modifies it in place)
  • Transferring ownership (the original variable gives up the value)

This is expressed through argument conventions:

fn read_value(borrowed x: Int):

    print(x)  # x is read-only here

fn modify_value(inout x: Int):

    x = x + 1  # x is modified in place

You do not need to master this on day one. But understanding that Mojo gives you control over memory, rather than leaving it entirely to a garbage collector, will help you make sense of error messages and design better-performing code as you go deeper.

💡 Did You Know?

Modular has benchmarked Mojo at over 35,000x faster than Python on certain numerical computing tasks. This is not because Mojo’s syntax is smarter, it is because Mojo compiles down to native machine code via LLVM and can leverage hardware features like SIMD that Python’s interpreter cannot access directly. For AI inference workloads, this kind of performance difference is genuinely transformative.

Where Can You Use Mojo?

Mojo is still a relatively young language, but its practical use cases are already well-defined. Here is where it makes the most sense right now:

AI Model Development: Writing custom neural network layers, attention mechanisms, or activation functions that need to run fast without depending on pre-built CUDA kernels.

High-Performance Inference: Deploying AI models in production environments where latency matters, Mojo can run inference significantly faster than Python-based pipelines.

Hardware Kernel Development: Writing low-level code that runs directly on GPUs, TPUs, or custom AI accelerators. Mojo’s SIMD and hardware intrinsics make this accessible without dropping into CUDA or C++.

Scientific Computing: Any domain that involves heavy numerical computation, physics simulations, genomics, and financial modelling can benefit from Mojo’s performance without giving up Python’s ecosystem.

Replacing C++ Extensions: Many Python libraries use C++ under the hood for performance. Mojo can replace those extensions with code that is easier to read, write, and maintain.

If you’re serious about learning languages like Mojo and want to apply them in real-world scenarios, don’t miss the chance to enroll in HCL GUVI’s Intel & IITM Pravartak Certified Artificial Intelligence & Machine Learning Course, co-designed by Intel. It covers Python, Machine Learning, Deep Learning, Generative AI, Agentic AI, and MLOps through live online classes, 20+ industry-grade projects, and 1:1 doubt sessions, with placement support from 1000+ hiring partners.

Conclusion

In conclusion, Mojo is one of the most interesting developments in programming languages for AI in recent years. It takes the Python syntax that millions of developers already know and pairs it with the kind of performance that has previously only been achievable by dropping into C++ or CUDA.

For anyone working in AI, machine learning, or high-performance computing, Mojo is worth paying close attention to. It is still evolving, but the foundations, static typing, LLVM compilation, SIMD support, and a clean ownership model, are solid.

The best way to get started is to set up your environment, write a few small programs, and start noticing how it differs from Python. The transition is gradual, and your existing Python knowledge is a genuine advantage.

As the Mojo ecosystem matures and library support expands, it has real potential to become the go-to language for production AI development.

FAQs

1. What is the Mojo programming language? 

Mojo is a high-performance programming language developed by Modular. It is designed as a superset of Python, adding static typing, manual memory control, and hardware-level access to deliver performance comparable to C++, while keeping Python’s familiar syntax.

2. Who created Mojo?

Mojo was created by Modular, a company founded by Chris Lattner, who also created the Swift programming language and contributed significantly to LLVM and Clang.

3. Is Mojo the same as Python? 

Mojo is not the same as Python, but it is designed to be compatible with it. Most Python syntax is valid in Mojo, but Mojo adds features like static typing, fn functions, structs, and direct hardware access that Python does not have.

4. How much faster is Mojo than Python? 

Modular has reported benchmarks showing Mojo running over 35,000x faster than Python on specific numerical tasks. Real-world performance gains vary by use case, but Mojo is consistently much faster for compute-heavy workloads.

MDN

5. Do I need to know Python to learn Mojo? 

Python experience is helpful because Mojo’s syntax is similar, but it is not strictly required. If you are new to both, starting with Python basics first will make learning Mojo more intuitive.

Success Stories

Did you enjoy this article?

Schedule 1:1 free counselling

Similar Articles

Loading...
Get in Touch
Chat on Whatsapp
Request Callback
Share logo Copy link
Table of contents Table of contents
Table of contents Articles
Close button

  1. What is Mojo?
  2. Why Was Mojo Created?
  3. Setting Up Your Mojo Environment
    • Option 1: Use the Mojo Playground (Easiest)
    • Option 2: Install Mojo Locally
    • Setting Up VS Code for Mojo
  4. Writing Your First Mojo Program
  5. Core Features of Mojo You Should Know
    • Static Typing
    • SIMD Support
    • Structs
  6. Working With Functions in Mojo
    • def: The Python-Compatible Way
    • fn: The Performance-Oriented Way
  7. Understanding Mojo's Type System
    • Primitive Types in Mojo
    • Type Inference
  8. Memory Management in Mojo
    • Ownership and Borrowing
  9. Where Can You Use Mojo?
  10. Conclusion
  11. FAQs
    • What is the Mojo programming language? 
    • Who created Mojo?
    • Is Mojo the same as Python? 
    • How much faster is Mojo than Python? 
    • Do I need to know Python to learn Mojo?