2017-01-10 89 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