0Pricing
Mojo Academy · Lesson

Defining a struct

Bundle fields into one type.

Why You Need a struct

When values belong together, like a point's x and y, you can bundle them into one custom type. In Mojo that bundle is a struct. 📦

The struct Keyword

You define a new type with the struct keyword, a name, and a colon. Everything indented under it belongs to that type.

struct Point:
    pass

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