Fix Python – Get last result in interactive Python shell

Question

Asked By – Edward Z. Yang

In many symbolic math systems, such as Matlab or Mathematica, you can use a variable like Ans or % to retrieve the last computed value. Is there a similar facility in the Python shell?

Now we will see solution for issue: Get last result in interactive Python shell


Answer

Underscore.

>>> 5+5
10
>>> _
10
>>> _ + 5
15
>>> _
15

This question is answered By – Mark Cidade

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0