2017-01-10 91 views
0

菜鸟问题probably..I正在读some code和疑惑线28:布尔等于-1

if len(files) == 0 or not files[0].endswith(".dcm") or root.find("sax") == -1: 
    continue 

那么,为什么在左侧的布尔运算等于-1(而不是0) ?

+0

'=='是一个真理比较。它没有看到这是否是一个布尔值。 – PHPglue

回答

4

str.find()返回-1如果没有找到提供的文本,root.find("sax") == -1正在检查。

,如果它是该生产线可能会有点更可读:

根据
if not files or files[0].endswith('dcm') or 'sax' not in root: 
+0

好吧,我忘了这个。非常感谢Will。 – Sen