Use _ to get the last evaluated value – Python Tips

In Python’s interpreter, we can use _ to get the last evaluated value. This could be useful if you don’t want to re-type the last evaluated value.

$ python3
Python 3.7.3 (default, Oct 7 2019, 12:56:13)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 + 2
3
>>> _
3
>>> 4 + _
7
>>>
$ python3
Python 3.7.3 (default, Oct  7 2019, 12:56:13) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 + 2
3
>>> _
3
>>> 4 + _
7
>>>
$ python3 Python 3.7.3 (default, Oct 7 2019, 12:56:13) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 1 + 2 3 >>> _ 3 >>> 4 + _ 7 >>>

Enter fullscreen mode Exit fullscreen mode

原文链接:Use _ to get the last evaluated value – Python Tips

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
I try to give up the dream just a dream.
努力了才叫梦想
评论 抢沙发

请登录后发表评论

    暂无评论内容