Can I use True and False like normal variables?


#1

Question

True and False seem like valid variable names, so can these be used like normal variables in Python?

Answer

No, True and False cannot be used like other variables. Reassigning these will result in a SyntaxError.

In Python, True and False are known as reserved words or keywords, which means they cannot be used as ordinary identifiers and cannot be reassigned like a variable.

This is an important implementation, because it would prevent issues like accidentally updating the values to something different, like True = 100 or False = True which would be an inconvenience when we need to utilize them in a program later on.