Functions are declared with fn:
fn
fn greet(name: str) -> str { return "Hello, {name}!" } print(greet("Alice"))
The return type is indicated with ->. The last value in a function can also be returned implicitly.
->
Goal: Create a function square that returns the square of a number and print square(7).
square
square(7)
Run the code to see the output
9 results