Why didn't my boolean work?


#1

Question

I wrote my code for the boolean and when I press Run it isn’t accepted; why is this?

Answer

Python, and all programming languages, require you to match their syntax exactly. Note that there are no quotation marks around a boolean value, and that they are capitalized. In other languages you may see booleans written as true and false, but in Python they must be True and False. Keep that in mind for future exercises where you’ll be asked to check if something is True or False so you don’t compare to a string, like ”True”!

Take a look at the code below for a better understanding:

bool_1 = True
bool_2 = False
bool_3 = true     # invalid
bool_4 = false    # invalid
bool_5 = "true"   # invalid
bool_6 = "false"  # invalid

FAQ: Learn Python - Python Syntax - Booleans
#2

I just started learning python today so not exactly an expert, but what I noticed is that this program is somewhat strict. you have to write True or False, the capital letters seem important for the first letters. So you cannot write tRue, trUe, truE, TruE and so on…


#3

i used lower case for false and it ran fine but only accepted capitalised true ???


#4

If True corresponds with number 1 why is name_is_maria = 1 incorrect; for age_is_12 I typed age_is_12 = 0 which worked.


#5

I have the same question, can someone advice please?


#6

i have the same question!
can someone help me get the answer?