掃二維碼與項目經理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網交流
在python中,任何對象都可以判斷其真假值:True,F(xiàn)alse

10余年的黔西南州網站建設經驗,針對設計、前端、開發(fā)、售后、文案、推廣等六對一服務,響應快,48小時及時工作處理。營銷型網站建設的優(yōu)勢是能夠根據用戶設備顯示端的尺寸不同,自動調整黔西南州建站的顯示方式,使網站能夠適用不同顯示終端,在瀏覽器中調整網站的寬度,無論在任何一種瀏覽器上瀏覽網站,都能展現(xiàn)優(yōu)雅布局與設計,從而大程度地提升瀏覽體驗。成都創(chuàng)新互聯(lián)從事“黔西南州網站設計”,“黔西南州網站推廣”以來,每個客戶項目都認真落實執(zhí)行。
在if或while條件判斷中,下面的情況值為False:
1.None
2.Flase
3.數值為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.
在運算操作和內建函數返回Boolean結果0或者Flase表示false(更多學習內容,請點擊Python學習網)
1或True表示true
python中的Boolean運算如下:
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))
運行結果:
>>> 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 >>>

我們在微信上24小時期待你的聲音
解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網交流