Version: 1.1.0

Operators

Mojo operators follow a familiar precedence: arithmetic, then comparison, then boolean logic. Parentheses make intent obvious.

Essentials

  • + - * / // % ** handle arithmetic. // is floor division.
  • == != < > <= >= compare values and produce Bool.
  • and, or, and not are the boolean operators.
  • & | ^ ~ << >> are bitwise.
  • A struct can supply the same operators by defining the matching dunder method.

Example

def main():
    print(2 + 3 * 4)
    print(7 == 7 and 1 < 2)
    print(1 << 3)

Keep in mind

Comparison chains such as 0 <= n < 10 are allowed and read the way they do in Python.