Editor settings

General settings

Save settings

Learn to program with Python

Inequality Operator #

The inequality operator !‏= is used to compare the inequality of two values or expressions, which is opposite to equality operator ==. It returns True if both values are not equal, and False when both values are equal.‎‎

Sometimes, the inequality operator shows up as != or !‏=, depending on the code editor you are using.

You can use an inequality operator by typing ! sign, followed by =, for example:

x = 10 != 20
print(x) # Output: True

y = "David" != "David"
print(y) # Output: False

In the first example, the expression 10 != 20 evaluates to True, and in the second example, the expression "David" != "David" evaluates to False.


Exercise #

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

Tests #

  • Variable equal should be False
  • Variable not_equal should be True
  • Use inequality operator !=
Output will be displayed here