Python基礎(3)if_else、for、while、break與continue

來源:互聯網
上載者:User

標籤:完全退出   退出   語言   基礎   完全   str   執行   for   ++   

1、if ... else
1 a=62 if a>=5:3     print("The a is bigger than 5")4 else:5     print("The a is smaller than 5")

2、for迴圈

1 #for i in range(10):#預設從0開始,步進為1相當於c語言for(i=0;i<10;i++)2 for i in range(1,10,3):#從1開始,步進為33     print("loop:", i )

3、while迴圈

1 count=02 while True:3     print("你是風兒我是沙,纏纏綿綿到天涯...",count)4     count +=1

4、break與continue

 1 #break用於完全退出本層迴圈 2 while True: 3     print ("break:123") 4     break 5     print( "456") 6  7 #continue用於退出本次迴圈,繼續下一次迴圈 8 while True: 9     print( "continue:123")10     continue11     print( "456")

5、while+else

#與其它語言else 一般只與if 搭配不同,在Python 中還有個while ...else 語句,while 後面的else 作用是指,
當while 迴圈正常執行完,中間沒有被break 中止的話,就會執行else後面的語句

 

Python基礎(3)if_else、for、while、break與continue

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.