Go on and go: what's the difference?

What is the difference between continue and pass in Python? I am new to Python and try to make my code look and act more professionally. I see their value, but for my unprepared mind, I see no clear difference. I looked here , but I could not understand what the main difference is. I noticed that continue shown in the loop example to continue the next loop, and pass is the "place owner" in the classes, etc.

I think my question is, how much are they needed? Should I focus on them now to add professionalism to my code, or is it more likely to take it or leave it as a script?

Thanks in advance for your reply.

+4
source share
2 answers

Pass

pass means you just fill in the place where instruction is usually required

 while True: pass # The pass is needed syntactically 

From the documentation:

pass is a null operation - when it is executed, nothing happens. It is useful as a placeholder if the statement is required syntactically, but the code should not be executed, for example:

Continue

continue proceeds to the next iteration, if any.

 i = 1 while i<5: continue # Endless loop because we're going to the next iteration i = i + 1 

From the documentation:

continue can only be found syntactically nested in a for or while loop, but not nested in a function or class definition or the final statement inside this loop. 6.1 It continues with the next loop of the closest closed loop.

+8
source

Pass is useful for creating functions that are not used. Does absolutely nothing . I sometimes use it when starting a new project to create functions that I will use later, but at the moment I do not need them.

Continue , starts the loop again with the next element in the iteration, which often occurs after the conditional.

+3
source

Source: https://habr.com/ru/post/1488192/


All Articles