Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我之前在阅读 Python 文档,发现<>. 这与 究竟有何不同!=?据我所知,唯一的区别是它<>不适用于字符串。是否<>做了一些特别的事情!=,或者有什么原因我两年多没有听说过?
<>
!=
<>是过去的残余。引用文档
!= can also be written <>, but this is an obsolete usage kept for backwards compatibility only. New code should always use !=.
另外,值得注意的是 Python 3 不支持<>.
<> 对于字符串或任何其他类型,与,完全相同!=:
>>> 'a' <> 'b' True >>> 'a' != 'b' True
但是,<>已弃用。它已从 Python 3中删除。始终使用!=。
运算符<>只是!=.
从文档中查看。