Not Operator (!)
A Not operator is represented by an exclamation mark (!). Technically, it’s a unary prefix operator, which means that you use it with one operand, and you code it immediately in front of that operand.
The Not operator reverses the value of a Boolean expression. Thus, if the expression is true, Not changes it to false. If the expression is false, Not changes it to true.
For example:
!(i = 4)
This expression evaluates to true if i is any value other than 4. If i is 4, it evaluates to false. It works by first evaluating the expression (i = 4). Then it reverses the result of that evaluation.
i != 4
The result is the same. The Not operator can be applied to any expression that returns a true-false result, however, not just to an equality test.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access