Boolean Values
So far, we have covered the basics of individual instructions that can be written as a program and fed to a computer. However, the real strength of programming isn't just running these instructions one after the other. It lies in the independence, flexibility and power it gives you by the option to skip instructions, repeat them, or choose several instructions to run. As a matter of fact, usually we wouldn't want our program to start running from the first line of code and simply execute every line, right to the end. Flow control statements can help us choose which instructions we want to execute under which conditions.
(Insert image for flow control)
While the Integer, Floating-point and String data types have millions of possibilities, the Boolean data type has only two values: True or False.
Interesting: Boolean is capitalized because the data type is named after mathematician George Boole.
When typed as Python code, the Boolean values True and False do not require the quotes we place around Strings, and they always start with a capital T or F, with the rest of the word in lowercase: True
or False
.
Tip: You can't use
True
orFalse
as a variable name, or it throws this error:SyntaxError: can't assign to keyword
.
Example for Implementation:
data = True
student = False