- Let's discuss python, not equal operators.
- In python, there are different types of operators available,in that we have not equal operators.
- Not equal to operator comes under the comparison operator as we compare the one variable with the other.
- Python not equal to the operator is used for the same data type values.
- When we compare one variable with another variable by using not equal operators we will get the boolean type values. bool type is True or False. if the values are not equal then it returns True value and if the values are equal then it returns the False value.
- The syntax for not equal to is != mostly used in the python 3 versions.
Python Not Equal Operator (!=) Explained with Examples
The not equal operator is one of the most commonly used comparison operators in Python. Whether you're comparing numbers, strings, or variables, understanding how != works is fundamental to writing clean conditional logic.
What Is the Not Equal Operator in Python?
In Python, the != operator checks whether two values are not equal to each other. It belongs to the family of comparison operators, and it always returns a boolean value — either True or False.
- If the two values are different, it returns True
- If the two values are same, it returns False
- Works with integers, floats, strings, lists, and more
- != is the standard syntax used in Python 3
Syntax
variable1 != variable2#1. write a python program to describe not equal to operator using integer
- a=2.5
- b=1.0
- c=5.0
- print(a!=b)
- true
- print(b!=c)
- true
- print(a!=b!=c)
- true
#2. write a python program to describe not equal to an operator using string
- Python, not equal operator using string
- x='apple'
- y='ball'
- print(x!=y)
output: true
#1. Python Not Equal Operator with Float Numbers
Let's start with a simple example comparing float values using !=:
a = 2.5
b = 1.0
c = 5.0
print(a != b) # True — 2.5 and 1.0 are different
print(b != c) # True — 1.0 and 5.0 are different
print(a != b != c) # True — all three values are different
Output:
True
True
True
Notice that a != b != c is Python's way of chaining comparisons. It checks that a is not equal to b, AND b is not equal to c — both in a single expression.
#2. Python Not Equal Operator with Integers
Works exactly the same with whole numbers:
x = 10
y = 20
print(x != y) # True — 10 and 20 are different
print(x != 10) # False — 10 and 10 are equal
Output:
True
False
#3. Python Not Equal Operator with Strings
String comparisons with != are case-sensitive. 'Apple' and 'apple' are treated as different values:
x = 'apple'
y = 'ball'
print(x != y) # True — different strings
print(x != 'apple') # False — same string
print('Apple' != 'apple') # True — case-sensitive!
Output:
True
False
True
#4. Using Not Equal in an if Statement
The most practical use of != is inside if conditions to control program flow:
username = "admin"
input_user = "guest"
if input_user != username:
print("Access denied. You are not the admin.")
else:
print("Welcome, admin!")
Output:
Access denied. You are not the admin.
Quick Reference Table
| Expression |
Result |
Reason |
| 5 != 3 |
True |
5 and 3 are different |
| 5 != 5 |
False |
Both values are equal |
| 'cat' != 'dog' |
True |
Different strings |
| 'cat' != 'cat' |
False |
Same string |
| 'Cat' != 'cat' |
True |
Case-sensitive comparison |
Key Points to Remember
- != is the standard not equal operator in Python 3
- Always returns a boolean — True or False
- Works across all data types: int, float, string, list, tuple
- String comparisons are case-sensitive by default
- Can be chained: a != b != c checks multiple values at once
The != operator is simple but powerful. Once you get comfortable using it in if statements, loops, and filters, you'll find yourself reaching for it constantly in real-world Python code.