Page 440 - ComputerScience_Class_11
P. 440
12.3 BOOLEAN
A Boolean (bool) is a logical data type that holds only two possible values, True and False. It represents the truth value
of a condition or expression in a program. Boolean data types are mainly used for decision-making, controlling the
flow of execution and performing logical operations such as checking conditions and combining multiple expressions.
Syntax of Boolean is as follows:
variable_name = True # Boolean True
another_variable = False # Boolean False
Program 4: To display the Boolean values in Python.
Program 4.py
File Edit Format Run Options Window Help
# Assigning Boolean value True to variable is_Morning
is_Morning = True
# Assigning Boolean value False to variable is_Night
is_Night = False
# Printing the value of is_Morning
print("Is it Morning? ", is_Morning)
# Printing the value of is_Night
print("Is it Night?", is_Night)
Output
Is it Morning? True
Is it Night? False
12.3.1 Characteristics of Boolean data types in Python
There are some characteristics of Boolean data types in Python:
• Logical Data Type: Boolean is a fundamental data type used to represent logical values in a program.
• Essential for Decision Making: It plays a key role in controlling program execution through conditional and looping
statements.
• Evaluates Conditions: Any expression that checks a condition returns a Boolean value (True or False).
• Supports Logical Expressions: Can be combined with logical operators such as and or and not to form complex
conditions.
• Automatically Evaluated: Many values in Python are automatically interpreted as Boolean in conditions (e.g., 0 is
treated as False, non-zero numbers as True).
• Immutable Nature: Boolean values cannot be modified once they are created.
12.4 SEQUENCE
Sequence data types in Python are collections of items that are stored in a particular order. Each item in the sequence
has a fixed position and we can access the items using their index number. These data types allow storing multiple
values in a single variable. The numbering of elements starts at index 0.
438 Touchpad Computer Science (Ver. 3.0)-XI

