Mojo Functions
Mojo Functions
In this tutorial, we will learn about Mojo Functions. A Mojo function is a self-contained block of code that performs a specific task. Functions organize code into manageable pieces to improve readability and promote reusability.
We can use the following keywords to declare Mojo Functions:
- fn
- def
The fn function enforces strict type checking and memory safety by requiring explicit type declaration and preventing accidental argument mutation.
Example
Let’s understand using an example. The code example snippet has two functions. One function is defined using the “def” keyword, and the other uses the “fn” keyword.
—
More information at Modular official website:
- https://www.modular.com/