Python not equal operator

后端 未结 4 1366
庸人自扰
庸人自扰 2020-11-30 14:56

I come from a c style languages, so I am natural in using != as not equal, but when I came to Python, from the documentation I read, I learned that for this pur

相关标签:
4条回答
  • 2020-11-30 15:25

    Python 2 supports both, in python 3 the <> operator has been removed.

    There is no difference between the two, but != is the preferred form.

    0 讨论(0)
  • 2020-11-30 15:29

    From the official docs you linked

    != can also be written <>, but this is an obsolete usage kept for backwards compatibility only. New code should always use !=.

    I believe the rationale for originally accepting <> was that it looked more natural for someone coming from a mathematical background than the common C-style != operator.

    0 讨论(0)
  • 2020-11-30 15:46

    I don't know what documentation you read, but I'm not aware of any that recommends <> over !=. PEP8, the main style guide, doesn't mention any such recommendation.

    0 讨论(0)
  • 2020-11-30 15:47

    Just for the record,<> has been obsolete since at least as early as version 1.4, which was released in October 1996.

    0 讨论(0)
提交回复
热议问题