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
equalto have the value ofFalseby using the inequality operator!=. - Create a variable
not_equalto have the value ofTrueby using the inequality operator!=.
Tests #
- Variable
equalshould beFalse - Variable
not_equalshould beTrue - Use inequality operator
!=
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules