Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does `<>` mean in Python?

I'm trying to use in Python 3.3 an old library (dating from 2003!). When I import it, Python throws me an error because there are <> signs in the source file, e.g.:

if (cnum < 1000 and nnum <> 1000 and ntext[-1] <> "s":     ... 

I guess it's a now-abandoned sign in the language.

What exactly does it mean, and which (more recent) sign should I replace it with?

like image 628
michaelmeyer Avatar asked May 25 '13 11:05

michaelmeyer


People also ask

What do 2 slashes mean in Python?

In Python, you use the double slash // operator to perform floor division. This // operator divides the first number by the second number and rounds the result down to the nearest integer (or whole number).

What does the '%' do in Python?

The % symbol in Python is called the Modulo Operator. It returns the remainder of dividing the left hand operand by right hand operand. It's used to get the remainder of a division problem.

What does <> mean in Python?

It means not equal to. It was taken from ABC (python's predecessor) see here: x < y, x <= y, x >= y, x > y, x = y, x <> y, 0 <= d < 10. Order tests ( <> means 'not equals')

What does [:: 1 mean in Python?

[::1] means: Start at the beginning, end when it ends, walk in steps of 1 (which is the default, so you don't even need to write it). [::-1] means: Start at the end (the minus does that for you), end when nothing's left and walk backwards by 1.


2 Answers

It means not equal to. It was taken from ABC (python's predecessor) see here:

x < y, x <= y, x >= y, x > y, x = y, x <> y, 0 <= d < 10

Order tests (<> means 'not equals')

I believe ABC took it from Pascal, a language Guido began programming with.

It has now been removed in Python 3. Use != instead. If you are CRAZY you can scrap != and allow only <> in Py3K using this easter egg:

>>> from __future__ import barry_as_FLUFL >>> 1 != 2   File "<stdin>", line 1     1 != 2        ^ SyntaxError: with Barry as BDFL, use '<>' instead of '!=' >>> 1 <> 2 True 
like image 91
jamylak Avatar answered Oct 06 '22 14:10

jamylak


It means NOT EQUAL, but it is deprecated, use != instead.

like image 21
Peter Varo Avatar answered Oct 06 '22 14:10

Peter Varo