程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python Programming Notes (6) loop and Python code implementation

編輯:Python

while loop

while Statement is very flexible , It can be used to repeatedly execute code blocks when the condition is true .

for loop

Is a sequence ( Or other iteratable objects ) Each element in the executes a code block .

Iterative dictionary

Use keys Wait for the dictionary method to get all the keys . If you're only interested in values , You can use d.values .

Some iterative tools

-- Parallel iteration

Iterating over several sequences simultaneously

-- Get index on iteration

Get the index of the current object while iterating the object sequence

-- Reverse iteration and sorting before iteration

reversed and sorted . They are similar to list methods reverse and sort ( sorted The accepted parameters are also related to sort similar ), But it can be used for any sequence or iteratable object , And do not modify the object in place , Instead, it returns the inverted and sorted version .

Out of the loop

--break

To end ( Jump out of ) loop , You can use break.

--continue

It ends the current iteration , And skip to the beginning of the next iteration .

-- while True/break precedent

while True Cause the cycle to never end , But you put the condition in one of the loops if In the sentence , And this one if Statement will call... When the condition is met break .

In the loop else Clause

Add a line to the loop else Clause , It's only when... Is not called break Execution only .

Friends who want complete code , can toutiao Search for “ Programming workshop ” After attention s Believe in me , reply “Python Programming Notes 6“ obtain

author : Programming workshop

Game programming , A game development favorite ~

If the picture is not displayed for a long time , Please use Chrome Kernel browser .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved