Boolean variables

So far we have seen textual variables as well as numeric integer variables. We will cover boolean variables and their use cases in the coming few exercises.
Boolean variables can only take two values True and False. They can represent if some statement holds a true condition or is a false statement.
is_better = True
sometimes = False
playing_football = True
hello = False

print(sometimes, playing_football)
This program would print False True as the value of sometimes is set to be False and the value of playing_football is set to be True.
 
To get types of variables we can use the type function.
a = True
b = 123
c = 'hello'

print(type(a), type(b), type(c), type(1234))
This program would print <class 'bool'> <class 'int'> <class 'str'> <class 'int'>. Meaning that:
  • a is of type bool (a boolean variable which can be either True or False)
  • b is of type int (a numeric integer variable)
  • c of type str (a textual/string variable)
  • 1234 is of type int (a numeric value)
 

Challenge

Create a numeric variable favorite and assign your favorite number to it. Create a variable best and assign True to it.
Your program should print the types of variables favorite and best in the output as well as the types of True, False, and 'long long text'.
 
To check your solution you need to sign in
Sign in to continue