0Pricing
Mojo Academy · Lesson

Writing an fn Function

Strict, typed, and performance-focused.

Meet the fn Keyword

The fn keyword defines a stricter function. It trades some flexibility for safety and the speed Mojo is famous for. ⚡

fn greet():
    print("Hello")

Types Are Required

Every parameter in an fn must declare its type. This lets the compiler check your code and generate fast machine code.

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

All lessons in this course

  1. Writing a def Function
  2. Writing an fn Function
  3. When to Reach for Each
  4. Return Types and None
← Back to Mojo Academy