4 ms·
_5 is a magic variable with the value of the output from cell 5. _ refers to the last output. Super handy when working interactively.
by wodenokoto 7y ago
_5 is a magic variable with the value of the output from cell 5. _ refers to the last output. Super handy when working interactively.
- numlocked 7y agoOh my god. I have used Jupyter notebooks for 7 years and never knew this. I just had to fire one up to verify -- and yep; exactly as described. How amazing! Thank you!
- spondyl 7y agoI believe the _5 syntax is specific to Jupyter, but in Python, the output of the last statement you execute is bound to _ For example, if you simply enter 4 into a Python REPL, printing _ will also print 4 It's really handy if you call a long statement in the REPL and forget to save the output to a variable I wrote about it once if you'd like to see some better examples: https://utf9k.net/blog/lost-python-results/ https://utf9k.net/blog/lost-python-results/
- ps101 7y agoYou just blew my mind.
- petters 7y agoI knew this, which may be handy when developing (assigning variables is superior IMO though) But in final output like this? I don't like it.
- wodenokoto 7y agoNo, you should not use output-references in code you share with people, but in my opinion it is one of the main reasons why jupyter notebooks in general put a large emphasis on displaying cell numbers