0Pricing
Mojo Academy · Lesson

Structs vs Python Classes

Why structs are static and fast.

They Look Similar

A Mojo struct and a Python class both bundle data with methods, so they feel familiar. But under the hood they are quite different. 🔍

Structs Are Static

A struct's layout is fixed at compile time. The compiler knows every field and type ahead, so it generates tight, fast code.

All lessons in this course

  1. Defining a struct
  2. Fields and the __init__ Method
  3. Adding Methods to a Struct
  4. Structs vs Python Classes
← Back to Mojo Academy