x = [1,2,3,4]
for i in x:
if i==2:
pass #Pass actually does nothing. It continues to execute statements below it.
print "This statement is from pass."
for i in x:
if i==2:
continue #Continue gets back to top of the loop.And statements below continue are executed.
print "This statement is from continue."
Đầu ra là
>>> This statement is from pass.
Một lần nữa, hãy để chạy cùng mã với những thay đổi nhỏ.
x = [1,2,3,4]
for i in x:
if i==2:
pass #Pass actually does nothing. It continues to execute statements below it.
print "This statement is from pass."
for i in x:
if i==2:
continue #Continue gets back to top of the loop.And statements below continue are executed.
print "This statement is from continue."
Đầu ra là -
>>> This statement is from pass.
This statement is from pass.
This statement is from pass.
This statement is from pass.
This statement is from continue.
This statement is from continue.
This statement is from continue.
đèo không làm gì cả. Tính toán không bị ảnh hưởng. Nhưng tiếp tục quay trở lại đầu vòng lặp để mua với tính toán tiếp theo.
Nguồn
2017-11-07 16:19:59
@ S.Lott: Ví dụ: 'while True :; pass # Busy-wait cho ngắt bàn phím (Ctrl + C) 'trong [tài liệu python] (http://docs.python.org/tutorial/controlflow.html#pass-statements) nhầm lẫn tôi trong cách, rằng tôi đã không không tìm thấy nó rõ ràng thời tiết nó cư xử tương đương với tiếp tục trong trường hợp này hoặc cái gì khác được dự định. Câu đầu tiên * "Câu lệnh pass không làm gì cả." * Mô tả tất cả các câu trả lời cho câu hỏi của tôi, nhưng bằng cách nào đó nó không lọt vào mắt tôi. – Aufwind