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
- Defining a struct
- Fields and the __init__ Method
- Adding Methods to a Struct
- Structs vs Python Classes