Library reference

Smaller of two values

Compare two values and return the smaller one.

min

Simple example

Start3 · 7
Result3
lesson.mojo
def main():
    print(min(3, 7))
Output
3
Advertisements

Everyday examples

Two buses charge 8 and 5 for the same trip. Which fare is cheaper?

Start8 · 5
Result5
lesson.mojo
def main():
    print(min(8, 5))
Output
5

A child wants 5 stickers. You have 3 left. How many can you give them?

Start5 · 3
Result3
lesson.mojo
def main():
    print(min(5, 3))
Output
3

Two walks to school take 12 and 9 minutes. How long is the quicker walk?

Start12 · 9
Result9
lesson.mojo
def main():
    print(min(12, 9))
Output
9

If both values are equal, the answer is that same value.

Run the example
Terminal
mojo lesson.mojo
Official documentation