Tags
python
Asked 2 years ago
19 Sep 2021
Views 366
Patricia

Patricia posted

What does <> mean in Python?

What does <> mean in Python?
sandip

sandip
answered Sep 19 '21 00:00

in general <> means not equal to operator.but,

in Python 3 :
<> means nothing in Python 3 , if you use <> in your python code , it will generate the error.

x="star"
y="moon"
if(x<>y):
     print("we are not in same ")

output :
if(x<>y):
^
SyntaxError: invalid syntax


so you cant use <> in the Python 3.
in Python 3 have alternative of <> is != or is not or operator.ne() method from operator module

so instead of using <> not equal to operator use alternative as below example:

!= not equal to exampe in Python

x="star"
y="moon"
if(x!=y):
     print("we are not in same ")

output: it will print "we are not in same"

is not not equal to exampe in Python

x="star"
y="moon"
if(x is not y):
     print("we are not in same ")

output : it will print "we are not in same"



operator.ne() not equal to exampe in Python

import operator
x="star"
y="moon"
if(operator.ne(x ,y)):
     print("we are not in same ")

output : it will print "we are not in same"
chirag

chirag
answered Sep 19 '21 00:00

Python version:2 have <> not equal to operator, which is used to check value of the two variable

<> work the same in Python as in other languages like c or PHP.

<> is the operation in Python 2.
<> is opposite of the == .

<> return boolean True , if both passed variable's value is not equal.
<> return boolean False if both passed variable's value is equal.


i=10
j=10
print(i<>j)


it will print boolean False because i and j are not equal.


i=10
j=1
print(i<>j)


it will print boolean True because i and j are not equal.
Post Answer