These operators compare the values on either sides of them and decide the relation among them. They are also called Relational operators.
Assume variable a holds 10 and variable b holds 20, then −
Operator | Description | Example |
---|---|---|
If the values of two operands are equal, then the condition becomes true. | (a b) is not true. | |
!= | If values of two operands are not equal, then condition becomes true. | (a != b) is true. |
<> | If values of two operands are not equal, then condition becomes true. | (a <> b) is true. This is similar to != operator. |
> | If the value of left operand is greater than the value of right operand, then condition becomes true. | (a > b) is not true. |
< | If the value of left operand is less than the value of right operand, then condition becomes true. | (a < b) is true. |
>= | If the value of left operand is greater than or equal to the value of right operand, then condition becomes true. | (a >= b) is not true. |
<= | If the value of left operand is less than or equal to the value of right operand, then condition becomes true. | (a <= b) is true. |
Oct 06, 2018 There's the!= (not equal) operator that returns True when two values differ, though be careful with the types because '1'!= 1.This will always return True and '1' 1 will always return False, since the types differ. Python is dynamically, but strongly typed, and other statically typed languages would complain about comparing different types. Python has two operators for equality comparisons, “is” and “” (equals). In this article I’m going to teach you the difference between the two and when to use each with a few simple examples.
Example
Assume variable a holds 10 and variable b holds 20, then −
Live DemoWhen you execute the above program it produces the following result −
How would you say does not equal?
Like
Is there something equivalent to that means 'not equal'?
haripkannan48011 gold badge99 silver badges1616 bronze badges
Aj EntityAj Entity1,91344 gold badges1212 silver badges1313 bronze badges
8 Answers
Use
!=
. See comparison operators. For comparing object identities, you can use the keyword is
and its negation is not
.e.g.
tskuzzytskuzzy29.2k1212 gold badges5858 silver badges125125 bronze badges
Not equal
!=
(vs equal )Are you asking about something like this?
This Python - Basic Operators chart might be helpful.
LevonLevon91.4k2525 gold badges167167 silver badges168168 bronze badges
There's the
!=
(not equal) operator that returns True
when two values differ, though be careful with the types because '1' != 1
. This will always return True and '1' 1
will always return False, since the types differ. Python is dynamically, but strongly typed, and other statically typed languages would complain about comparing different types.There's also the
else
clause:The
Peter Mortensenis
operator is the object identity operator used to check if two objects in fact are the same:14.2k1919 gold badges8888 silver badges114114 bronze badges
Samy VilarSamy Vilar7,97811 gold badge2525 silver badges3131 bronze badges
You can use both
!=
or <>
.However, note that
Malek B.Malek B.!=
is preferred where <>
is deprecated.78811 gold badge88 silver badges1010 bronze badges
Seeing as everyone else has already listed most of the other ways to say not equal I will just add:
in this case it is simple switching the check of positive (true) to negative and vise versa...
gabeiogabeio
There are two operators in Python for the 'not equal' condition -
a.) != If values of the two operands are not equal, then the condition becomes true. (a != b) is true.
b.) <> If values of the two operands are not equal, then the condition becomes true. (a <> b) is true. This is similar to the != operator.
Peter Mortensen14.2k1919 gold badges8888 silver badges114114 bronze badges
user128364user128364
Use
!=
or <>
. Both stands for not equal.The comparison operators
<>
and !=
are alternate spellings of the same operator. !=
is the preferred spelling; <>
is obsolescent. [Reference: Python language reference]EhsanEhsan
cgastaldcgastald
protected by Community♦Feb 9 '17 at 10:36
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?