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

Python0 Basics - Getting Started - Proficient (8)

編輯:Python

Last issue review:

In the last issue, we understood and learned ternary operations and and;or;not in logical operations.

Overview of this issue:

In this issue, we will learn about the while loop in the future.

Content of this issue:

     if Judgment can choose to do something, but it can only be done once, if you have to repeat the judgment a lottime?This is where our while loop comes into play.

# Assign value a is 1a = 1# enter the loopwhile a < 5:print(a)a += 1'''The while loop cannot stop by itself, so add a += 1'''

     whileUse andifclassesLike, sentencedtruewhenRunIndent the code insideCode, the judgment span is falsetimesstop looping;Usewhilespan> Attention should be paid to the loop:The loop must be able to stop;Note whether the judgment formula can beFake.

    The process of the whole loop is just like the above table, and it is executed in sequence until the end of the loop.

a = 1while a < 5:print(a)a += 1else:print("End of loop")

The while loop can also be followed by an else loop. When the loop ends normally, the code in the else will be executed.

a = 1while True:if a % 5 == 0:breakprint(a)a += 1else:print("End of loop")

while can also follow True directly, but internally you must use break to terminate the loopA loop terminated with break is the content of the else that will not be executed.

Summary:

We learned about the while loop in this issue


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