4

Can someone please point out what the point of assigning the result(s) of a plot to a dummy variable _ is like so:

_ = plt.plot(x_vers, y_vers, marker = '.', linestyle = 'none')

Usually I see code like this:

plt.plot(x_vers, y_vers, marker = '.', linestyle = 'none')

Is it better practice to use the dummy _ even if it is never used? if so, why?

cs0815
  • 16,751
  • 45
  • 136
  • 299

1 Answers1

3

plt.plot returns an matplotlib.AxesSubplot object or an array of them, depending on what you're plotting. If you're running that command in an interactive environment, and don't want its output dumped to output when run, you can either assign to a dummy variable or suppress with a semi-colon, but the latter isn't really pythonic.

If you're running a script, it makes no difference, because nothing is printed to stdout unless explicitly printed.

cs95
  • 379,657
  • 97
  • 704
  • 746