Course Content
Introduction to Python
Introduction to Python
Boolean Data Type in Python
Python has the boolean (or logical) data type. Booleans can only have one of two values: True
or False
. This type is primarily used for evaluating logical conditions. Below are the logical operators for comparison:
==
equal to;!=
not equal to;>
greater than;<
less than;>=
greater than or equal to;<=
less than or equal to.
When you use these operators, the result is a boolean value: True
if the condition is met and False
if it is not.
# Check if `1` equals `1` print(1 == 1) # Check if `"abc"` equals `"aBc"` print("abc" == "aBc") # Check if `87*731` greater than or equal to `98*712` print(87*731 >= 98*712)
What do these results mean? The first True
confirms that 1
is equal to 1
, which is self-evident. The second False
indicates that the strings "abc"
and "aBc"
are different because string comparisons in Python are case-sensitive—the letter 'b' in "abc"
is lowercase, while 'B' in "aBc"
is uppercase. The final False
shows that 87 * 731
is not greater than or equal to 98 * 712
. In fact, 63597
is less than 69776
.
Now, let's evaluate the following:
- Is the variable
first_integer
less than or equal tosecond_integer
? (It should returnTrue
iffirst_integer
is less than or equal tosecond_integer
, andFalse
if it is greater.) - Is the string
"text"
different from"TEXT"
? - Does the length of the string
"Python"
equal6
?
Note
Printing an expression like
variable_1 >= variable_2
does not mean thatvariable_1
is actually greater than or equal tovariable_2
. Instead, it simply evaluates whether the statement is True or False. This operation does not modify the values of the variables in any way.
Thanks for your feedback!