Python For Kids (Part 24: Bool Primitive Data Type)
Kevin Thomas
Director of Test Automation and Author of the world’s most popular Reverse Engineering Tutorial
For a complete table of contents of all the lessons please click below as it will give you a brief of each lesson in addition to the topics it will cover. https://github.com/mytechnotalent/Python-For-Kids
Today we are going to discuss the bool primitive data type. This is literally nothing more than True or False, a number greater than 1 or 0.
Today will be a shorter lesson as I would like to get deeper into the concept of bool when we get into conditional logic such as using if, elif and else logic however I wanted to introduce the concept in its basic form.
STEP 1: Open Mu IDE
STEP 2: Type Code
is_hungry = True print(type(is_hungry)) print(is_hungry > 0) print(is_hungry <= 0) # When you compare two values, the expression is eval to either True # or false print(100 > 1) print(100 < 10) print(42 == 42) print(42 != 42)
print(42 == 4)
STEP 3: Click Save
STEP 4: Save File - main.py - Desktop
STEP 5: Click Run
STEP 6: Review Output
Here we see the following:
<class 'bool'> True False True False True False False >>>
We see that our variable is in fact a bool and we can see the result of each comparison and whether it resolves to True or False above such as 100 > 1 which we know is True and 100 < 10 which we know is False, etc.
HOMEWORK:
I would like to you try a few more examples and re-run them so you get a better idea of how this works. Remember that bool are nothing more than a the evaluation of whether something is True or False or the setting of a var to True or False that we can use when we get into conditional logic in a later lesson.
This is the FUN part of learning when we apply our new knowledge and experiment on our own it REALLY helps us learn these concepts so please take your time and try a number of different numbers :)
In the next lesson we discuss the bytes primitive data type.