Core programming fundamentals · Lesson 5 of 60 · Code lesson, JavaScript or Python · Optional
Operators
Operators are symbols that work on values: arithmetic (+ - * / %), comparison (> < ==), logical (and, or, not), assignment (= and +=), and bitwise (& and |, which work on binary digits).
An expression such as 9 % 4 pairs an operator with its values, and % gives the remainder after dividing.
Multiplication and division happen before addition and subtraction, and brackets change the order.
Worked example
In JavaScript, console.log(9 % 4) prints 1, the remainder of 9 divided by 4. The logical operators are && (and), || (or) and ! (not).
console.log(2 + 3);
console.log(9 % 4);Output:
5 1
In Python, print(9 % 4) prints 1, the remainder of 9 divided by 4. The logical operators are the words and, or and not.
print(2 + 3)
print(9 % 4)Output:
5 1
Your turn
Change the first line to print the sum of 4 and 6, and the second line to print the remainder when 17 is divided by 5.
Expected output:
10 2
Loading your practice…
Preparing your workspace…