Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (2016, retired 2019) Lists Removing Items From A List

aditya yadav
aditya yadav
1,505 Points

What does the pass keyword do ? Is it equivalent to break statement

Pls answer

2 Answers

Steven Parker
Steven Parker
231,236 Points

A pass is essentially a "do nothing" statement.

It's usually used as a placeholder where a statement is required but you're not ready to create the actual code yet. It's handy for testing other sections of code before the entire project is finished.

Particularly in older languages, this kind of statement was known as a "no-op" (no operation).

Is it similar to continue then in terms of the functionality when he used it in the code (he didn't use it as a placeholder, he literally didn't have anything to put in there). If we kept it empty as opposed to writing pass would that create an error?

Steven Parker
Steven Parker
231,236 Points

A continue redirects the program flow back to the beginning of a loop, but a pass does not.

Steven Parker I thought continue just skipped for example

names = ["John", "Jack", "Quit", "Jill"]
for name in names:
    if name == "Quit":
        continue
    print(name)

What is printed: John, Jack, Jill

If it redirects the program to the beginning of the loop then the print wouldn't work, so what is continue? Skipping or redirecting or what?

Side Note:if I did not even use pass and left it empty, would there be an error?

Steven Parker
Steven Parker
231,236 Points

I think we are using the words "redirects" and "skipped" to describe the same thing. The difference in functionality in the example you gave is that with the continue there, only 3 words are printed. But if you replace it with pass, then all 4 words would be printed.