The Boolean data type can be one of two values, either True or False. Booleans are used to represent the truth values that are associated with the logic branch of mathematics, which informs algorithms in computer science.
Whenever you see the data type Boolean, it will start with a capitalised B because it is named for the mathematician George Boole. The values True and False will also always be with a capital T and F respectively, as they are special values in Python.
Many operations in maths give us answers that evaluate to either True or False:
500 > 100 True
1 > 5 False
200 < 400 True
4 < 2 False
5 = 5 True
500 = 400 False
Like with numbers, we can store a Boolean value in a variable:
my_bool = 5 > 8
We can then print the Boolean value with a call to the print() function:
Since 5 is not greater than 8, we will receive the following output:
As you write more programs in Python, you will become more familiar with how booleans work and how different functions and operations evaluating to either True or False can change the course of the program.
Write a program that demonstrates the boolean output for a Less Than.
Write a program that demonstrates the boolean output for a Less Than, More Than and Equal To.
Write a program to see if two strings are identical.
Thanks [name] from [whichclass][location], Mr McG will get your message…"
[message]"…and will get back to you ASAP via [email]. Catch you soon.
Have a great day!!
K McGuinness - 2018
No personal data will be shared with any third party. The only data processed via this website is anonymous browsing data to best manage your user experience.