Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Boolean Data Type in Python | Conditional Statements in Python
Introduction to Python
course content

Course Content

Introduction to Python

Introduction to Python

1. First Acquaintance with Python
2. Variables and Types in Python
3. Conditional Statements in Python
4. Other Data Types in Python
5. Loops in Python
6. Functions in Python

book
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.

12345678
# 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)
copy

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:

  1. Is the variable first_integer less than or equal to second_integer? (It should return True if first_integer is less than or equal to second_integer, and False if it is greater.)
  2. Is the string "text" different from "TEXT"?
  3. Does the length of the string "Python" equal 6?

Note

Printing an expression like variable_1 >= variable_2 does not mean that variable_1 is actually greater than or equal to variable_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.

question-icon

Fill in the blanks to complete the task.

# Check the following statements
print(first_integersecond_integer)
print("text""TEXT")
print(len("Python")6)
True
True
True

Click or drag`n`drop items and fill in the blanks

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 1
We're sorry to hear that something went wrong. What happened?
some-alt