我有一個線陣,在位置值5可以是下列值:你如何檢查是否變量等於在python
"Tablespace Free Space (MB)", "Tablespace Space Used (%)"
如果line[5]
是任何這些,我需要做一些額外的工作。
我已經試過這樣:
if (line[5] in ("Tablespace Space Used (%)")|("Tablespace Free Space (MB)"))
# some other code here
我不斷收到此錯誤:
if (line[5] in ("Tablespace Space Used (%)"|"Tablespace Free Space (MB)"))
^
SyntaxError: invalid syntax
你缺少一個':'在結束你的線。 – merlin2011 2015-02-11 21:08:32
您需要在if語句的末尾添加':'。例如:如果'(行[5]中( 「用於表空間的空間(%)」, 「表空間可用空間(MB)」):' – Andrew 2015-02-11 21:08:53
此外,關係或蟒是 「或」,而不是管 – sharjeel 2015-02-11 21:19:30