ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 26 Dec 2017 20:16:35 +0100Using the result of a previously evaluated cellhttps://ask.sagemath.org/question/40293/using-the-result-of-a-previously-evaluated-cell/ What is the proper way of using the result of a previous evaluated cell or the result of a previous line in the same cell if said result has not been named?Sun, 24 Dec 2017 18:25:37 +0100https://ask.sagemath.org/question/40293/using-the-result-of-a-previously-evaluated-cell/Answer by tmonteil for <p>What is the proper way of using the result of a previous evaluated cell or the result of a previous line in the same cell if said result has not been named?</p>
https://ask.sagemath.org/question/40293/using-the-result-of-a-previously-evaluated-cell/?answer=40296#post-id-40296Tou can use the *underscore* as follows:
sage: 1+1
2
sage: a = _ + 1
sage: a
3
Sun, 24 Dec 2017 23:39:46 +0100https://ask.sagemath.org/question/40293/using-the-result-of-a-previously-evaluated-cell/?answer=40296#post-id-40296Comment by danielvolinski for <p>Tou can use the <em>underscore</em> as follows:</p>
<pre><code>sage: 1+1
2
sage: a = _ + 1
sage: a
3
</code></pre>
https://ask.sagemath.org/question/40293/using-the-result-of-a-previously-evaluated-cell/?comment=40297#post-id-40297thanks, I'll tryMon, 25 Dec 2017 00:36:43 +0100https://ask.sagemath.org/question/40293/using-the-result-of-a-previously-evaluated-cell/?comment=40297#post-id-40297Answer by slelievre for <p>What is the proper way of using the result of a previous evaluated cell or the result of a previous line in the same cell if said result has not been named?</p>
https://ask.sagemath.org/question/40293/using-the-result-of-a-previously-evaluated-cell/?answer=40309#post-id-40309For a previously evaluated cell in a Jupyter notebook, you can use `Out[...]`,
replacing `...` by the number of the output cell you want to refer to.
Example.
In[1]: 1 + 1
Out[1]: 2
In[2]: 20 + 20
Out[2]: 40
In[3]: Out[1] * 5
Out[3]: 10
-----
EDIT (2018-01-05).
Note that this also works in the Sage REPL (read-eval-print loop), or "command-line interface",
ie, using Sage in a terminal. The reason is that, like Jupyter, it uses IPython behind the scenes.
The difference is that the cell numbers are not displayed there... They still exist though.
Example:
$ sage -v
SageMath version 8.1, Release Date: 2017-12-07
$ sage -q
sage: 1 + 1
2
sage: 20 + 20
40
sage: Out[1] * 5
10
If you want to get one of the last few cells and want to figure out what is the current number,
you could ask the length of `In` or the length of `Out`.
Example:
$ sage -v
SageMath version 8.1, Release Date: 2017-12-07
$ sage -q
sage: 1 + 1
2
sage: 9 * 9
81
sage: len(Out)
2
sage: Out[2]
81
There might be a way of making Sage display the numbering of the input and output...
But I don't know how to do it!Tue, 26 Dec 2017 20:16:35 +0100https://ask.sagemath.org/question/40293/using-the-result-of-a-previously-evaluated-cell/?answer=40309#post-id-40309