python逻辑运算符的使用_总结Python中逻辑运算符的使用
下表列出了所有python語言支持的邏輯運(yùn)算符。假設(shè)變量a持有10和變量b持有20,則:
示例:
試試下面的例子就明白了所有的python編程語言提供了邏輯運(yùn)算符:
#!/usr/bin/python
a = 10
b = 20
c = 0
if ( a and b ):
print "line 1 - a and b are true"
else:
print "line 1 - either a is not true or b is not true"
if ( a or b ):
print "line 2 - either a is true or b is true or both are true"
else:
print "line 2 - neither a is true nor b is true"
a = 0
if ( a and b ):
print "line 3 - a and b are true"
else:
print "line 3 - either a is not true or b is not true"
if ( a or b ):
print "line 4 - either a is true or b is true or both are true"
else:
print "line 4 - neither a is true nor b is true"
if not( a and b ):
print "line 5 - either a is not true or b is not true"
else:
print "line 5 - a and b are true"
當(dāng)執(zhí)行上面的程序它會(huì)產(chǎn)生以下結(jié)果:
line 1 - a and b are true
line 2 - either a is true or b is true or both are true
line 3 - either a is not true or b is not true
line 4 - either a is true or b is true or both are true
line 5 - either a is not true or b is not true
如您對(duì)本文有疑問或者有任何想說的,請(qǐng)點(diǎn)擊進(jìn)行留言回復(fù),萬千網(wǎng)友為您解惑!
總結(jié)
以上是生活随笔為你收集整理的python逻辑运算符的使用_总结Python中逻辑运算符的使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql移动数据的语句是_mysql基
- 下一篇: python中函数的定义实例_Pytho