Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

assign results to dummy variable _ [duplicate]

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?

like image 511
cs0815 Avatar asked Sep 12 '25 00:09

cs0815


1 Answers

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.

like image 169
cs95 Avatar answered Sep 14 '25 14:09

cs95