2018年1月22日 星期一

[Python] 第二篇--判斷式

[Python] 第二篇--判斷式

在python的判斷式if(), elif(), else後面都要加":"

1. 單向判斷式

if(3<4):
    print("T")

輸出:
T

2. 雙向判斷式

if(3>4):
    print("T")
else:
    print("F")

輸出:
F

3. 多向判斷式

if(3>4):
    print("3")
elif(4>4):
    print("4")
else:
    print("F")

輸出:
F

4. 巢狀判斷式

if(100<1000): #true
    if(100 < 10): #false
        print("100<1000 and 100 < 10")
    else:
        print("100<1000 and 100 > 10")
else:
    print("100>1000")

輸出:
100<1000 and 100 > 10

沒有留言:

張貼留言