Python(或通用编程).为什么使用<>而不是!=,并且存在风险吗? [英] Python ( or general programming ). Why use <> instead of != and are there risks?
问题描述
我认为,如果我理解正确,a <> b
在功能上与a != b
完全相同,并且在Python not a == b
中完全相同,但是是否有理由在其他版本上使用<>
?对于Python新手来说,我知道一个常见的错误是认为not a is b
与a != b
或not a == b
相同.
I think if I understand correctly, a <> b
is the exact same thing functionally as a != b
, and in Python not a == b
, but is there reason to use <>
over the other versions? I know a common mistake for Python newcomers is to think that not a is b
is the same as a != b
or not a == b
.
-
<>
是否会发生类似的误解,或者功能完全相同? - 它在内存,处理器等方面的成本是否更高?
- Do similar misconceptions occur with
<>
, or is it exactly the same functionally? - Does it cost more in memory, processor, etc.
Python 2中的
推荐答案
<>
是!=
的确切同义词-没有理由使用它,除了无用的异质性(样式问题)之外也没有缺点. ).长期以来一直不鼓励这样做,现在已在Python 3中将其删除.
<>
in Python 2 is an exact synonym for !=
-- no reason to use it, no disadvantages either except the gratuitous heterogeneity (a style issue). It's been long discouraged, and has now been removed in Python 3.
这篇关于Python(或通用编程).为什么使用<>而不是!=,并且存在风险吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!