Negation
Sometimes it's useful to negate a condition, changing it from true to false or vice versa. For example, if we had a variable raining
and wanted to run a block of code if it is not raining, we would write it without negation like this:
raining = False
if raining == False:
print("It's not raining")
With the help of negation (not
):
raining = False
if not raining:
print("It's not raining")
This might not seem very useful now, but in certain cases, such as when you have many conditions connected by logical operators, it can be easier to think about certain parts as negated.
Instructions
Use an if
statement to print I'm going out
if the internet is not working.
Start programming for free
8/10