運算子 | 描述 |
例子
|
---|---|---|
in |
如果在指定的順序找到則計算結果為true,否則變數結果值為false
|
x in y,這裡在一個1的結果,如果 x 是序列 y 的成員
|
not in |
如果不能在指定的順序找到則計算結果為true,否則變數為 false
|
x ont in y,這裡在一個1的結果,如果 x 不是序列 y 成員 |
#!/usr/bin/python3 a = 10 b = 20 list = [1, 2, 3, 4, 5 ] if ( a in list ): print ("Line 1 - a is available in the given list") else: print ("Line 1 - a is not available in the given list") if ( b not in list ): print ("Line 2 - b is not available in the given list") else: print ("Line 2 - b is available in the given list") c=b/a if ( c in list ): print ("Line 3 - a is available in the given list") else: print ("Line 3 - a is not available in the given list")
Line 1 - a is not available in the given list Line 2 - b is not available in the given list Line 3 - a is available in the given list