treyhunner, Python tip 💡
If you just ran an expression in the #Python REPL and you'd like to capture its value into a variable, you don't need to run it again!
You can use the _ variable to get the value of the last REPL output!
You'll also sometimes see _ used as a throwaway variable:
>>> from random import randint
>>> numbers = [randint(1, 5) for _ in range(10)]_ works in the built-in Python REPL and pretty much all third-party REPLs.
Try _ out yourself in a REPL: https://pym.dev/repl
Add comment