View on GitHub

python-for-kids

Learning and exercise content on Python for Kids

Day 8 - Boolean : True/False Value

Boolean or Ture/False value is an important data type in any programming language. When you think and plan to write a program often you have to check if something is True then do something or if a value is more than some value. These are the common scenario you might come across in your planning and wrting phase. Let’s understand some use cases.

When you do calculation, you generally smaller number with bigger number else the result will be negative. So you want to validate that if a value is more than the other value then do the calculation. Imagine the below example,

i = 10
j = 9

if i > j then
    //do the calculation

Here you are considering if j is smaller than i then do the calculation else dobn’t do anything. We will have more of these kinds of conditions when we learn about if..else.. in Python.

In Python you can directly print the Ture or False value from the expression. We will see few examples here,

print(10 > 8)  # Output: True
print(10 > 11) # Output: False

You can even assign a value to a variable and it would become boolean

bln = (10 > 9)
print(type(bln)) # Output: <class, 'bool'>

Watch the video

Video link

Day 8 - Exercise

  1. Imagine two values and try to use various different operators like >, <, ==, != etc to check the output by using print() function.

Next: Day 9 - if…else condition

Back to Index