0 votes

I have seen many tutorials where they put pass at the end of each function, example

func say_hello():

I would like to know what this means, I have programming knowledge, specifically in Python and according to me this has no function, I don't know if in Godot is different, but the amount of people I have seen doing it is considerable. I have applied tests by putting and removing the pass but the result is the same, thanks in advance.

asked Jun 26 in Engine by Jalkhov (35 points)

1 Answer

+3 votes
Best answer

pass really just prevents parsing errors when a function would otherwise be empty, or when some language element requires an indented portion.

In your above example, it's meaningless.

There's a related answer here:


answered Jun 26 by jgodfrey (5,670 points)
selected Jun 26 by Jalkhov

Exactly, I had already used that article, that's why I made the query, because it really doesn't make any sense, what I think is that maybe the people I've seen don't want the errors to be displayed, because they write perfectly functional functions but still add the pass at the end. But examples like the one I presented I've seen many. Well, I had that doubt because actually in almost every tutorial I've seen, they do, thank you.

Part of it may be that some people "stub out" a new function with just a function name, but no actual body to begin with. In that case, the pass is required to prevent parsing errors.

Then, later, they add the function body and probably just forget or don't bother to remove the pass.

While that doesn't hurt anything, it's meaningless at that point.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.