Reputation: 9103
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
Reputation: 9103
Add a semicolon to the end of the expression. For the above example:
plt.xticks(range(3), ['A', 'B', 'C']);
Upvotes: 3