why pass statement?
M-a-S
NO-MAIL at hotmail.com
Tue Sep 16 18:30:03 EDT 2003
"Hans Nowak" <hans at zephyrfalcon.org> wrote in message news:mailman.1063743501.23038.python-list at python.org...
> 'pass' is a no-op statement that, according to the tutorial, is used when a
> statement is required syntactically but the program requires no action.
I know. I just state that there is NO need for it. Just define in __builtins__
pass = None and that's it.
BTW Algol-68 used 'skip' for both purposes (no action and no data).
> Your code, using None, has the same effect. However, there's a slight
> difference in the bytecode that is generated:
>
> >>> def f(): pass
> ...
> >>> def g(): None
> ...
> >>> import dis
> >>> dis.dis(f)
> 1 0 LOAD_CONST 0 (None)
> 3 RETURN_VALUE
> >>> dis.dis(g)
> 1 0 LOAD_GLOBAL 0 (None)
> 3 POP_TOP
> 4 LOAD_CONST 0 (None)
> 7 RETURN_VALUE
>
> This is probably irrelevant, but it wouldn't be correct to say that using pass
> is exactly the same as using None.
>
> HTH,
>
> --
> Hans (hans at zephyrfalcon.org)
> http://zephyrfalcon.org/
That's just a question of optimization.
And thank you for showing me how to dig to the code!
M-a-S
More information about the Python-list
mailing list