`<>` 在 Python 中是什么意思? [英] What does `<>` mean in Python?

查看:80
本文介绍了`<>` 在 Python 中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Python 3.3 中使用一个旧库(可追溯到 2003 年!).当我导入它时,Python 会抛出一个错误,因为源文件中有 <> 符号,例如:

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

我想这是该语言中现已废弃的标志.

它到底是什么意思,我应该用哪个(最近的)标志替换它?

解决方案

表示不等于.它取自 ABC(python 的前身)参见 这里:

<块引用>

<代码>x = y, x >y,x=y,xy, 0 <= d <10

顺序测试(<> 表示'不等于')

我相信 ABC 来自 Pascal,这是 Guido 开始使用的编程语言.

它现在已在 Python 3 中删除.请改用 !=.如果您CRAZY,您可以废弃!= 并使用这个复活节彩蛋:

<预><代码>>>>从 __future__ 导入 barry_as_FLUFL>>>1 != 2文件<> 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

这篇关于`&lt;&gt;` 在 Python 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆