On Mon, Jul 23, 2018 at 2:03 AM Jonathan Fine <[email protected]> wrote:
> Thank you for your attention. What have I missed?
>
None and a few other things are special-cased by CPython. The compiler
won't bother to write bytecode instructions when an if-statement obviously
evaluates false. That might surprise some folks.
In [1]: import dis
In [2]: def foo():
...: if None:
...: print(1)
...: if 0:
...: print(2)
...: if 'a' == 'b':
...: print(3)
...:
In [3]: dis.dis(foo)
6 0 LOAD_CONST 1 ('a')
2 LOAD_CONST 2 ('b')
4 COMPARE_OP 2 (==)
6 POP_JUMP_IF_FALSE 16
7 8 LOAD_GLOBAL 0 (print)
10 LOAD_CONST 3 (3)
12 CALL_FUNCTION 1
14 POP_TOP
>> 16 LOAD_CONST 0 (None)
18 RETURN_VALUE
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/