ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 23 Apr 2020 10:25:46 -0500It is possible to use a previous output?https://ask.sagemath.org/question/50961/it-is-possible-to-use-a-previous-output/I dont find anything in the documentation about the possibility to re-use previous outputs, in jupyter notebook or in the prompt, so I will ask here: there is a command to reuse a previous output instead to avoid recompute it again?
By example, say that I compute a value of a function and I want to re-use again this result, there is a way to call for the oputput instead of re-computing it value again or pre-assigning the value to a variable? Of course a solution could be just copy-and-paste the output, by I want to know if there is a command to avoid also this manipulation.Thu, 23 Apr 2020 09:19:00 -0500https://ask.sagemath.org/question/50961/it-is-possible-to-use-a-previous-output/Answer by Sébastien for <p>I dont find anything in the documentation about the possibility to re-use previous outputs, in jupyter notebook or in the prompt, so I will ask here: there is a command to reuse a previous output instead to avoid recompute it again? </p>
<p>By example, say that I compute a value of a function and I want to re-use again this result, there is a way to call for the oputput instead of re-computing it value again or pre-assigning the value to a variable? Of course a solution could be just copy-and-paste the output, by I want to know if there is a command to avoid also this manipulation.</p>
https://ask.sagemath.org/question/50961/it-is-possible-to-use-a-previous-output/?answer=50964#post-id-50964SageMath command line and Jupyter notebook are both based on ipython. As described in the section [Output caching system](https://ipython.readthedocs.io/en/stable/interactive/reference.html#output-caching-system) of the documention of ipython, the underscore `_` stores the previous result. The double underscore `__` stores the pre-previous and triple underscore `___` stores the pre-pre-previous:
sage: 10 * 10
100
sage: _ + 1
101
sage: __ + 3
103
sage: ___ + 5
105
You may also use the list `Out` which stores all of the results:
sage: Out
{1: 100, 2: 101, 3: 103, 4: 105}
or `_<n>` where `n` the n-th output from the start:
sage: _3
103Thu, 23 Apr 2020 10:25:46 -0500https://ask.sagemath.org/question/50961/it-is-possible-to-use-a-previous-output/?answer=50964#post-id-50964