"""
if語句練習
if 語句 and or not 規則運算:
if 多個條件:
and 並列
x and y
or 或者
x or y
not 非
not x
"""
"""
if語句練習
if 語句 and or not 規則運算:
if 多個條件:
and 並列
x and y
or 或者
x or y
not 非
not x
"""a=10
b=20
######## and
if a and b:
print("a,b都為真")
else:
print("a,b有乙個不為真")
######## or
if a or b:
print("a,b至少有乙個為真")
else:
print("a,b都不為真")
######## not
print("*****************************")
a=0print("a=0時")
if a and b:
print("a,b都為真")
else:
print("a,b有乙個不為真")
if a or b:
print("a,b至少有乙個為真")
else:
print("a,b都不為真")
if not(a and b):
print("false")
else:
print("true")
執行結果:
//例:and練習
input_name=input("請輸入使用者名稱:")
input_age=input("請輸入年齡:")
if input_name=="tom" and input_age=="18":
print("歡迎%s"% input_name)
else:
print("輸入錯誤")
輸出 b
a=10
b=20
r=a>b and a or b
print(r)
運算結果:
mysql 動態邏輯運算 MySQL 邏輯運算子
not 10 10 not 1 1 1 1 not 1 1 not null 0 0 1 1 0 null 2 邏輯與 and 或 1 當所有運算元均為非零值 並且不為 null 時,所得值為 1 2 當乙個或多個運算元為 0 時,所得值為 0 3 其餘情況所得值為 null mysql selec...
04 Python檔案操作
f open 我的檔案.txt r encoding utf8 開啟乙個檔案 讀模式 f.close 關閉檔案解釋 寫 過程中,很容易忘記關閉檔案,所以出現了with語句。with open 我的檔案.txt r encoding utf8 as file 自動關閉檔案 data file read...
python邏輯運算子
python邏輯運算子 python語言支援邏輯運算子,以下假設變數 a 為 10,b為 20 運算子 邏輯表示式 描述 例項 and x and y 布林 與 如果 x 為 false,x and y 返回 false,否則它返回 y 的計算值。a and b 返回 20。or x or y 布林...