比較運算子

a,b=10,30
print('a>b嗎?',a>b)
print('a<b嗎?',a<b)
print('a<=b嗎?',a>=b)
print(a is b)#這個比較的是id標識
a>b嗎? False
a<b嗎? True
a<=b嗎? False
False
一個變數有三部分組成:1標識,2型別,3值
比較物件的標識使用is
布爾運算子

print(a==1 and b==2)#ture and true-->ture
print(a==1 and b<2)#ture and false-->false
print(a!=1 and b==2)#false and ture-->false
print(a!=1 and b!=2)#false and false -->false
print('---------------or 或者-----------------------------------------')
print(a==1 or b==2)#ture or true-->ture
print(a==1 or b<2)#ture or false-->ture
print(a!=1 or b==2)#false or ture-->ture
print(a!=1 or b!=2)#false and false -->false
print('---------------not 對運算元取反-----------------------------------------')
f=True
f2=False
print(not f)
print(not f2)
print('---------------in 與not in-----------------------------------------')
s='helloworld'
print('w'in s)
print('k'in s)
print('w'not in s)
print('k'not in s)
True
True
False
False
False
---------------or 或者-----------------------------------------
True
True
True
False
---------------not 對運算元取反-----------------------------------------
False
True
---------------in 與not in-----------------------------------------
True
False
False
True
python中的位運算子


運算子的優先級



p27
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/393964.html
標籤:其他
