Operators

Lesson 3 of 20

Add, compare, repeat and split values with operators — and watch precedence pick the order for you.

The big picture

The symbol toolbox

Operators are the punctuation of math and logic — a handful of symbols that compute, compare and combine values.

Math first

+ - * / and % do arithmetic; ** raises to a power: 2 ** 3 is 8.

Division gotcha

Two Integers divided stay Integer: 7 / 2 is 3, and % grabs the leftover 1.

Comparisons

==, !=, < and > return true or false — perfect for feeding an if.

Logic glue

&& means both, || means either, and ! flips the answer.