pass at the end of a function

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Jalkhov

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.

:bust_in_silhouette: Reply From: jgodfrey

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://forum.godotengine.org/19110/difference-between-pass-and-return

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.

Jalkhov | 2020-06-26 16:17

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.

jgodfrey | 2020-06-26 17:13