1

After some long computations, I obtain

%//ExpandAll

Out[0]

I want to know the meaning of Out[0]. Does this mean my expression % is zero?

Gert
  • 1,530
  • 8
  • 22
phy_math
  • 873
  • 4
  • 9

1 Answers1

1

No, this does not mean your answer is 0. If you look at the documentation of Out then it says that: Out[n] is a global object that is assigned to be the value produced on the n-th output line. Out[0] is undefined since you always start evaluation at line 1. The result you get is most probably caused by a statement of the form % as a first evaluation or %% when only 1 line was evaluated or %0.

To get rid of such results try to avoid using the % operation and assign results of calculations to symbols. So, e.g., instead of writing

(x+1)^2

Expand[%]

use

p = (x+1)^2;

Expand[p]

Gert
  • 1,530
  • 8
  • 22
  • I'm confused, I thought the Out function was a good standard practice. But, I prefer temp variables to retain useful values, all the time. I like your answer. But when are Out values useful? Perhaps, just true temporary values? – prog9910 Dec 06 '21 at 19:01
  • 1
    @prog9910 there's really nothing wrong with using % in an interactive session with a notebook. Eventually when you know you want to do something with the result of a calculation you start assigning a variable as shown in this answer. But the issue you are seeing is explained here: your kernel quit during the long computation, so when you call % there is no previous output to refer to. – Jason B. Dec 06 '21 at 20:42
  • As Jason points out: its not bad practice when you're using the notebook interactively. Even then I would advise to use Out[n] instead of % since the value of % changes with every evaluation and as is the case above: its not always clear what its value used to be at some point in the notebook. The reason that using Out[n] is not always the best choice is that either (1) you have infinite history length (i.e. Out[n] is stored for all n), which might induce crashes or (2) you have a finite history length but then the value of Out[n] might be removed at some point. – Gert Dec 06 '21 at 20:50