Search⌘ K

The Not Operator

Explore how to use the unary not operator in Rust to invert boolean values from true to false and vice versa. This lesson helps you write clearer conditional code by understanding how the ! operator works and how it differs from other comparison operators like == and !=. You will also test your understanding with practical exercises to reinforce the concept.

We'll cover the following...

Personally, I find is_hot() == false to be a bit weird to read. If we were having a conversation, I wouldn’t say “make sure that it is hot is false.” I wouldn’t say “make sure that it is hot is not true.” A more normal way to say this is “make sure that it is not hot.” The not ...