Sanmveg saini
Sanmveg saini

Reputation: 750

What is the difference b/w != and <> comparison operator in python?

Look in the following website:
TutorialPoint

There under the heading of Python Comparison Operators:

You will see that it is written that != is similar to <> operator
and even I tested this thing.

So what is the main difference between these two comparison operators?

Also there are documents that say they are similar, and not the same. Is there different criteria for the comparison for these two comparison operators?

Upvotes: 1

Views: 140

Answers (3)

sandipon
sandipon

Reputation: 986

As described in the documentation, they are the same.<> is deprecated and was removed in Python 3, so you should use !=.

Upvotes: 2

falsetru
falsetru

Reputation: 368894

According to Expressions - Comparisons - Python 2.x documentation:

The forms <> and != are equivalent; for consistency with C, != is preferred; where != is mentioned below <> is also accepted. The <> spelling is considered obsolescent.

And, <> is gone in Python 3.x. Don't use <> if possible.

Upvotes: 2

Kevin
Kevin

Reputation: 76184

In 2.7, they're the same. From the documentation:

The comparison operators <> and != are alternate spellings of the same operator. != is the preferred spelling; <> is obsolescent.

In 3.X, <> no longer exists.

Upvotes: 7

Related Questions