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.
精彩评论