`<>` 在 Python 中是什么意思? [英] What does `<>` mean in Python?
问题描述
我正在尝试在 Python 3.3 中使用一个旧库(可追溯到 2003 年!).当我导入它时,Python 会抛出一个错误,因为源文件中有 <>
符号,例如:
if (cnum <1000 and nnum <> 1000 and ntext[-1] <> "s":...
我想这是该语言中现已废弃的标志.
它到底是什么意思,我应该用哪个(最近的)标志替换它?
表示不等于.它取自 ABC
(python 的前身)参见 这里:
<代码>x
顺序测试(<>
表示'不等于')
我相信 ABC
来自 Pascal,这是 Guido 开始使用的编程语言.
它现在已在 Python 3 中删除.请改用 !=
.如果您CRAZY,您可以废弃!=
并使用这个复活节彩蛋:
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?
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
这篇关于`<>` 在 Python 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!