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

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

8/10

Negation | Start Coder