Boolean
Part of the Fundamentals section of Coddy's Python journey — lesson 6 of 77.
A bool (Boolean) type has only 2 possible values: True or False.
Note that these values are case-sensitive, meaning they must start with a capital letter.
Here is an example of assigning a bool value to a variable:
variable_true = True
variable_false = FalseIn the above, two variables named variable_true and variable_false are initialized, with the values True and False respectively.
Booleans are the building blocks for creating logic in the programs we write. We have a whole chapter about logic and conditions.
Challenge
BeginnerDeclare a variable named boolean and assign it the value True.
Cheat sheet
A bool (Boolean) type has only 2 possible values: True or False.
These values are case-sensitive, meaning they must start with a capital letter.
Assigning bool values to variables:
variable_true = True
variable_false = FalseBooleans are fundamental for creating logic in programs.
Try it yourself
# Type your code below
boolean = ?
# Don't change the line below
print(f'boolean = {boolean}')This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 48Loops
For LoopWhile LoopBreakContinueRecap - FactorialThe Range FunctionNested LoopRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators9Functions
Declare a FunctionArgumentsReturnRecap - Sigma FunctionRecap - Validation FunctionDefault Values12Iterating Over Sequences
Iterating Over ElementsThe Enumerate FunctionIterating Over Strings Part 1Iterating Over Strings Part 2