Boolean Values

We said that all conditions are ultimately true (True) or false (False). We can verify this by printing the condition:

print(10 < 20) # Prints: True
condition = 10 != 10
print(condition) # Prints: False

These True and False values are called Boolean values. We can also directly use these values in code. For example:

condition = True # True
if condition:
	print("This is always printed")

And we can also compare them:

True == True # True
True == False # False
True != False # True

This may not seem very useful now, but you will see later that Boolean values are really useful.

Instructions

Create a variable discount with the value True.

If discount is true (True), print I will buy!.

Start programming for free

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

Or sign up with:

5/10

Boolean Values | Start Coder