开发者

python interpreter with ellipsis _ function?

>>> type(_)
<type 'ellipsis'>

>>> 1 + 1
2
>>> _
2
>开发者_JS百科>> 

what's the usefulness of this _ function?


It just makes it easier to track intermediate values or to operate on the previously returned value.

>>> [x*x for x in range(5)]
[0, 1, 4, 9, 16]
>>> sum(_) # instead of having to type sum([0,1,4,9,16]) by hand
30


in case you use ipython it's part of ipythons [output caching system] - it just stores the previous output.

edit: oh, it seems to be implemented for the default python interpreter as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜