预计阅读本页时间:-
General Format
In its most complex form, the while statement consists of a header line with a test expression, a body of one or more indented statements, and an optional else part that is executed if control exits the loop without a break statement being encountered. Python keeps evaluating the test at the top and executing the statements nested in the loop body until the test returns a false value:
while <test>: # Loop test
<statements1> # Loop body
else: # Optional else
<statements2> # Run if didn't exit loop with break