The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

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

func say_hello():
    print("Hello")
    pass

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.

in Engine by (38 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:

https://godotengine.org/qa/19110/difference-between-pass-and-return

by (22,674 points)
selected by

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.