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