South Plantation High School logo
South Plantation High School · Procedural Programming with Python

Relational, Logical & Identity Operators Practice

==  !=  <  >  <=  >=  ·  and  or  not  ·  is  is not

Instructions

The information on this page is not stored. If you start an assignment, you must finish it. This page does not save your progress.

Programs make decisions by asking questions that have a True or False answer. Python has three groups of operators for asking these questions. Every expression below produces a Boolean value: True or False.

1. Relational (comparison) operators

Relational operators compare two values. In the examples below, x = 7.

OperatorMeaningExampleResult
==equal tox == 7True
!=not equal tox != 7False
>greater thanx > 10False
<less thanx < 10True
>=greater than or equal tox >= 7True
<=less than or equal tox <= 6False

2. Logical operators: and, or, not

Logical operators combine or flip True/False values. They are lowercase English words in Python (not &&, || or ! like some other languages).

ABA and BA or B
TrueTrueTrueTrue
TrueFalseFalseTrue
FalseTrueFalseTrue
FalseFalseFalseFalse
  • and is True only when both sides are True.
  • or is True when at least one side is True.
  • not flips one value: not True is False and not False is True.
age = 15
print(age >= 13 and age <= 19)  # True

3. Identity operators: is, is not

== asks "do these have the same value?" is asks "are these the very same object in memory?" is not asks the opposite.

a = [1, 2]
b = a           # b points to the SAME list as a
c = [1, 2]      # c is a NEW list with the same values
print(a == c)   # True   same values
print(a is c)   # False  different objects
print(a is b)   # True   same object

4. Order: which part does Python do first?

When operators are mixed, Python works in this order: (1) comparisons such as ==, <, is, then (2) not, then (3) and, then (4) or. Parentheses always go first, so use them to make your meaning clear.

print(True or False and False)     # True   and goes first: True or (False and False)
print((True or False) and False)   # False  parentheses change the order

How this works

  1. Enter your first name, last name initial, and class period, then click Start Assignment. Your start time is recorded.
  2. The assignment opens in a Python editor with three files (tabs) and 30 problems. Complete every orange dashed box and drop down.
  3. Click ▶ Run on any part to see what Python would print in the terminal. Run does not grade you, so check your work carefully.
  4. When you finish all three tabs, click Submit for Score. Your end time is recorded and your score appears. Answers cannot be changed after submitting.
PartTaskProblemsPoints
1Predict whether each line prints True or False126 (½ point each)
2Choose the operator that completes each line105 (½ point each)
3Type the missing operator84 (½ point each)
Total3015

Student Information

Reminder: nothing on this page is saved. Once you click Start Assignment, plan to finish before you leave or refresh the page.