Operators and Expressions
Operators combine values into expressions: arithmetic, comparison, logical and assignment.
Beginner
An expression is anything that produces a value, built from operands and operators:
- Arithmetic:
+ - * / %(%is the remainder:7 % 3is1). - Comparison:
== != < > <= >=— produce true/false. - Logical: AND, OR, NOT (
&& || !in C/Java,and or notin Python). - Assignment:
=, plus shortcuts like+=.
Precedence decides the order: 2 + 3 * 4 is 14, not 20. Use parentheses when in doubt.
Watch out for integer division: in C and Java, 7 / 2 is 3; in Python 3 it is 3.5 (use // for 3).
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.