【发布时间】:2014-12-27 13:33:26
【问题描述】:
以下函数返回None:
In [5]: def f():
...: pass
所以我对这个输出并不感到惊讶:
In [8]: dis.dis(f)
2 0 LOAD_CONST 0 (None)
3 RETURN_VALUE
In [10]: f.__code__.co_consts
Out[10]: (None,)
好的,这是有道理的。但现在,考虑以下函数:
In [11]: def g():
....: return 1
In [12]: dis.dis(g)
2 0 LOAD_CONST 1 (1)
3 RETURN_VALUE
In [13]: g.__code__.co_consts
Out[13]: (None, 1)
g没有使用None,那为什么在co_consts中呢?
【问题讨论】:
标签: python python-2.7 python-internals