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."
La salida es
>>> This statement is from pass.
Nuevamente, deje correr el mismo código con cambios menores.
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."
La salida es -
>>> 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.
El pase no hace nada. La computación no se ve afectada. Pero continuar vuelve al principio del ciclo para avanzar con el siguiente cálculo.
Raviteja Ainampudi
fuente
while True:; pass # Busy-wait for keyboard interrupt (Ctrl+C)
en los documentos de Python me confundió en el camino, que no me pareció que el tiempo fuera claro, se comporta de manera equivalente a continuar en este caso o se pretendía algo más. La primera oración "La declaración de aprobación no hace nada". caracteriza todas las respuestas a mi pregunta, pero de alguna manera no me llamó la atención.