Booleans Introduction

An introduction to the Boolean data type in Python

Booleans Introduction

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:

greater than
500 > 100 True
1 > 5 False

less than
200 < 400 True
4 < 2 False

equal
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:

print(my_bool)

Since 5 is not greater than 8, we will receive the following output:

False

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.

Introduction

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.

3.1 Booleans Introduction Task
Submit your completed task...
If you need to get in touch with Mr McG then this is the way….

What's your name?
image/svg+xml
Thank you [name], that's great.

Can I ask where you are from?
image/svg+xml
Hey [name], can I ask where you are from?
image/svg+xml
Hey [name], which class are you in?
image/svg+xml
OK [name], thanks for that.

I will need your email address so I can get back to you!!
image/svg+xml
Thanks [name], nearly there.

What can I help you with?
image/svg+xml

Thanks [name] from [whichclass][location], Mr McG will get your message…"
[message]"…and will get back to you ASAP via [email]. Catch you soon.

image/svg+xml
Thank you [name], Mr McG got your message.
Thanks [name], Mr McG will get back to you as soon as he can!!

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.