Python 條件式 Condition

除了重複使用Function,有時我們須檢查結果,依此判斷下個步驟該怎麼進行,如此就需要條件式 condition statement。

if ... elif ... ese ( 或 if ... elif ...elif 或 if .. else )

while

>>> def numIsEven(k):
...    if k % 2 == 0:
...       print(k,' is even')
...    else:
...       print(k,' is odd')
...
>>> numIsEven(8)
8  is even
>>> numIsEven(7)
7  is odd

 

 

 

 

/end

posted @ 2019-08-20 16:56  太川  阅读(181)  评论(0编辑  收藏  举报