Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

python/sage: how to get the last expression?

$
0
0

If I do in Jupiter (in both python and sage) something like:

a = 42b = 43a + b

it will, somehow, manage to understand that this process returns the value a + b, i.e. 85 here:

enter image description here

Similarly, if I just do:

a = 42

it will understand that there is nothing to return.

I would like now to do something similar for a different application (to cache the result of a python operation)… how could I get this information, ideally by just running the code and appending some python code to obtain this information? I tried to do:

a = 42b = 43a + bprint(_)

but this fails. I was thinking to do something stupid like adding res = in front of the last line, but it might fail for instance if the last line is indented etc… How can I elegantly obtain this information?


Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>