2
我有以下字符串條件檢查與str.endswith()
mystr = "foo.tsv"
或
mystr = "foo.csv"
鑑於這種情況,我希望上面的兩個字符串始終打印 「OK」。 但它爲什麼會失敗?
if not mystr.endswith('.tsv') or not mystr.endswith(".csv"):
print "ERROR"
else:
print "OK"
什麼是正確的做法?
請注意,endswith()也接受一個元組:'if not mystr.endswith(('.tsv',「.csv」)):' – alecxe