Coquelicot
Coquelicot

Reputation: 9103

How can I stop the value of an expression from being echoed in an IPython notebook?

Sometimes a function I wish to call for side effects also happens to return some value I don't care about. If I call that function without assigning its return value to a variable, IPython will echo it in the cell's output. For example:

%matplotlib inline
from matplotlib import pyplot as plt

plt.plot([1, 2, 5])
plt.xticks(range(3), ['A', 'B', 'C'])

In addition to the plot, my output contains:

([<matplotlib.axis.XTick at 0xb074c94c>,
  <matplotlib.axis.XTick at 0xaf3d2a2c>,
  <matplotlib.axis.XTick at 0xaf6d986c>],
 <a list of 3 Text xticklabel objects>)

Which is the return value of the call to plt.xticks. Is there a better way to suppress this output than assigning the return value to a dummy variable?

Upvotes: 1

Views: 137

Answers (1)

Coquelicot
Coquelicot

Reputation: 9103

Add a semicolon to the end of the expression. For the above example:

plt.xticks(range(3), ['A', 'B', 'C']);

Upvotes: 3

Related Questions