Back to Course

Introduction to Python

0% Complete
0/0 Steps
  1. Python: Basics
    14Topics
    |
    15 Quizzes
  2. Python: Control Flow
    12Topics
    |
    12 Quizzes
  3. Python: Errors
    5Topics
    |
    5 Quizzes
Lesson 2, Topic 6
In Progress

Python: Boolean Operator And

Yasin Cakal 17 Oct 2021
Lesson Progress
0% Complete

Frequently, the conditions that your conditional statement will check will require more than one boolean expression. In these cases, you can use boolean operators to construct larger boolean expressions. These logical operators combine smaller boolean expressions to form larger boolean expressions. Here are the three boolean operators that we will go over:

  • and
  • or
  • not

In this lesson, we will start with the boolean operator and, which combines two boolean expressions and returns True if both of its components are True, but False otherwise. Notice that even if a portion of an expression is True, the entire expression is False due to having a False statement. Let’s take a look at some examples:

# Returns True
print(1+1==2 and 2+2==4)
# Returns False
print(1+1==2 and 2+2==22)

# All possible combinations:
print(True and True)
print(True and False)
print(False and True)
print(False and False)

Output:

True
False
True
False
False
False

%d bloggers like this: