0Pricing
Mojo Academy · Lesson

Parameterized Functions

Specialize a function with [bracket] parameters.

Functions With a Parameter

A parameterized function takes a compile-time value in square brackets, letting one definition adapt itself before the program runs. ⚙️

fn repeat[count: Int](msg: String):
    for i in range(count):
        print(msg)

The Bracket List

Place your parameters in brackets right after the function name, then your normal arguments in parentheses just after that.

fn scale[factor: Int](x: Int) -> Int:
    return x * factor

All lessons in this course

  1. Parameters vs Arguments
  2. Parameterized Functions
  3. Parameterized Structs
  4. Why Compile-Time Wins Speed
← Back to Mojo Academy