Editor settings

General settings

Save settings

Learn to program with Python

Equality Operator #

Python comparison operators are used to compare two values and return a boolean value (True or False) based on the result of the comparison. The equality operator == (double qual signs) is used to compare the equality of two values or expressions.

For example:

x = 10 == 20
print(x) # Output: False

y = "David" == "David"
print(y) # Output: True

In the first example, the expression 10 == 20 evaluates to False, so x is assigned the value of False.

In the second example, the expression "David" == "David" evaluates to True, so y is assigned the value of True.


Exercise #

  • Create a variable equal to have the value of True by using the equality operator ==.
  • Create a variable not_equal to have the value of False by using the equality operator ==.

Tests #

  • Variable equal should be True
  • Variable not_equal should be False
  • Use the equality operator ==
Output will be displayed here