新聞中心
在python中,任何對(duì)象都可以判斷其真假值:True,F(xiàn)alse

10余年的黔西南州網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。營(yíng)銷型網(wǎng)站建設(shè)的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整黔西南州建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。成都創(chuàng)新互聯(lián)從事“黔西南州網(wǎng)站設(shè)計(jì)”,“黔西南州網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
在if或while條件判斷中,下面的情況值為False:
1.None
2.Flase
3.數(shù)值為0的情況,如:0,0.0,0j
4.所有空序列,如:'',(),[]
5.所有空mapping,如:{}
6.instances of user-defined classes, if the class defines a __Bool__() or __len__() method,
when that method returns the integer zero or bool value False.
All other values are considered true — so objects of many types are always true.
在運(yùn)算操作和內(nèi)建函數(shù)返回Boolean結(jié)果0或者Flase表示false(更多學(xué)習(xí)內(nèi)容,請(qǐng)點(diǎn)擊Python學(xué)習(xí)網(wǎng))
1或True表示true
python中的Boolean運(yùn)算如下:
print('x or y -> if x is false,then y, else x ')
x, y= 2,0
print('{} or {} = {}'.format(x, y, xor y))
x1, y1= 0,10
print('{} or {} = {}'.format(x1, y1, x1or y1))
x2, y2= 0,0
print('{} or {} = {}'.format(x2, y2, x2or y2))
print('#' * 50)
print('x and y -> if x is false,then x, else y ')
print('{} and {} = {}'.format(x, y, xand y))
x1, y1= 0,10
print('{} and {} = {}'.format(x1, y1, x1and y1))
x2, y2= 0,0
print('{} and {} = {}'.format(x2, y2, x2and y2))
print('#' * 50)
print('not x -> if x is false,then True,else False ')
x= 2
print('not {} = {}'.format(x,not x))
x= 0
print('not {} = {}'.format(x,not x))
運(yùn)行結(jié)果:
>>> x or y -> if x is false,then y, else x or 0 = 2 or 10 = 10 or 0 = 0 ################################################## x and y -> if x is false,then x, else y and 0 = 0 and 10 = 0 and 0 = 0 ################################################## not x -> if x is false,then True,else False not 2 = False not 0 = True >>>
分享標(biāo)題:創(chuàng)新互聯(lián)Python教程:小白必看的python中的Bool運(yùn)算和真假值
網(wǎng)頁(yè)地址:http://m.5511xx.com/article/cosdgoe.html


咨詢
建站咨詢
