Python 判斷和迴圈 if for while

2021-10-21 20:54:52 字數 559 閱讀 7909

if

例:age = int(input('what is your age : '))

if age < 20 :

print('有點小喲')

elif age < 24 :  # elif 是 else if的縮寫 , 在python裡面寫法為 elif

print('你才畢業不久吧')

else 

print('畢業很久了吧')

迴圈

for

例:for x in [1,2,3,4,5,6]:

if x == 3:

continue   # continue語句會直接繼續下一輪迴圈,後續的print()語句不會執行

print(x)

while

例:n=10

while n>0

print(n)

n = n - 2

if n == 6:

break  #break 跳出迴圈

Python 判斷和迴圈

python中 是有意義的,乙個製表符或者4個空格代表一行 段 aaaaaaaaaa bbbbbbbbbbb bbbbbbbbbbb ccccccccc ccccccccc bbbbbbbbbbb bbbbbbbbbbb上面共有三個 塊,包含關係如下,c行被b行包含,b 塊有被a包含。age 12 ...

python 判斷 迴圈和迭代

f1 引號中什麼都沒有,表示false 引號中有空白字元,表示true if f1 print true else print false furry input small input if furry if small print it s a cat.else print it s a bea...

python 條件判斷和迴圈

一 條件判斷 if if age 18 記住在判斷語句後面要加上 還有要注意他的縮排 age 20 if age 18 print your age is age print adult else x 還有就是 if 條件1 x elif 條件2 x elif 條件3 x else x 迴圈 迴圈這...