我使用的是python3.6和pycharm。在
我的一行代码说:
If oim.sent != None:
Pycharm给出了以下措辞非常强硬的警告:
That type of comparisons should always be done with 'is' or 'is not', never the equality operators.
但是,我使用这一行代码来区分None
和{
编辑:
我误解了警告。我想这是在指示我使用if not oim.sent:
,当然,它不会区分None
和{if oim.sent is not None:
这只是一个警告,因为您没有遵循python准则。你的代码运行正常。如果需要,最好使用:
if oim.sent is not None:
但是,您当然可以使用
!= None
速度更快,而且是惯用的Python,因此每个人都知道您知道自己在做什么;-)
相关问题 更多 >
编程相关推荐