why pass statement?
NO-MAIL at hotmail.com
Wed Sep 17 00:30:03 CEST 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.
> Hans (hans at zephyrfalcon.org)
That's just a question of optimization.
And thank you for showing me how to dig to the code!
More information about the Python-list