Practice question · Sort into groups
Sort each operator by its role.
Groups: Comparison operator · Boolean operator · Assignment operator
- !=
- =
- or
=
- ==
- and
Hints
- Comparisons produce a boolean; boolean operators combine booleans; assignment stores a value.
- The single = is not a comparison at all, however much it looks like one.
Show the answer
Comparison operator: ==, !=,
=
Boolean operator: and, or
Assignment operator: =
Why
== , != and >= compare and yield true or false; 'and' and 'or' combine booleans; the single = assigns. Filing = under comparison is exactly the bug the lesson warns about: writing = where == is meant tries to assign inside a condition.
Practise Conditionals and Logical Branching
The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Conditionals and Logical Branching
- A grading program runs: if score >= 90 give A; elif score >= 80 give B; elif score >= 70 give C; else give F.…
- With short-circuit evaluation, in the expression A or B, if A is true then B is still always evaluated.
- Python makes if x = 5 a syntax error while C compiles it happily. What is C's version actually doing?
- if x = 5 is a common bug in languages where it is legal, while if x == 5 is what was meant. Why is the…