Booleans and conditionals
Booleans, named after George Boole, take the values of True or False. Although the idea behind Booleans is rather simple, they make programming much more powerful.
When writing programs, it’s useful to consider multiple cases. If you prompt the user for information, you may want to respond differently, depending on the user’s answer.
For instance, if the user gives a rating of 0 or 1, you may give a different response than a rating of 9 or 10. The keyword here is if
.
Programming based on multiple cases is often referred to as branching. Each branch is represented by a different conditional. Conditionals often start with an if
clause, followed by else
clauses. The choice of a branch is determined by Booleans, depending on whether the given conditions are True
or False
.
Booleans
In Python, a Boolean class object is represented by the bool
keyword and has a value of True
or False
.
Note
Boolean values must be capitalized in Python...