Implementing PyCharm code cells

Code cells in PyCharm are defined by lines of code that start with the following characters: #%%. These lines are treated as standard comments in the low-level execution of Python, but PyCharm will recognize them as code cell separators in its editor. Let's see this feature in action:

  1. In our current program, add those lines so that your program is similar to the following:
import numpy as npimport matplotlib.pyplot as plt#%% generate random dataN = 100x = np.random.normal(0, 1, N)y = np.random.normal(2, 3, N)#%% plot data in histogramsplt.hist(x, alpha=0.5, label='x')plt.hist(y, alpha=0.5, label='y')plt.legend(loc='upper right')plt.show()

As you can see, we can actually put comments in these code cell separators, ...

Get Hands-On Application Development with PyCharm now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.