match = re.search('...', str, re.IGNORECASE)
if match is not None:
pass
# or
if match != None:
pass
什么是好?
match = re.search('...', str, re.IGNORECASE)
if match is not None:
pass
# or
if match != None:
pass
什么是好?
从PEP 8:
比较像无单身应始终
is
或is not
,从来没有平等的运营商来完成。
哇.. 好的,非常感谢! – avasin 2014-10-27 18:52:15
@AaronHall你可以创建自己的singletons http://stackoverflow.com/questions/42558/python-and-the-singleton-pattern http://stackoverflow.com/questions/31875/is-there-a-simple-优雅的方式来定义单身在Python中 – 2014-10-27 19:06:27
这可能会更好,如果添加到您的答案,以免它被解释不同。 – 2014-10-27 19:42:31
'匹配不是无' – 2014-10-27 18:49:03
既不是更好,因为它们的行为不同。 – rightfold 2014-10-27 18:49:43
'is'是一个身份运算符,所以它应该只在检查对象是否具有_same_内存地址时使用(单例如无限定)。要小心,因为'hello'=='hello',但'hello'不是'hello'' – polvoazul 2014-10-27 18:55:18