BITFUTURISTIC

Freelance Engineer, Husband, Father and Obsessed with Technology

Python Memory

| Comments

Sleep deprivation can prove useful…

Finally my sleep deprivation has proven useful, I’ve learned a new python feature! Because you’re probably more interested in the python feature than my sob story about getting no sleep (again) I’ll get to the point.

In the Python interpreter the single underscore ‘_’ returns the last answer that was returned on the interpreter. It will probably make more sense if I just show you…(especially in my sleep deprived state.) >>> 4 4 >>> _ 4 This is an interesting feature. But you need to remember that it will be evaluated again at the end of each output. This means that if you string together a number of lines, all of which would return their answer to the interpreter and not a stored value, you’ll be working on the previous lines result for each ‘_’ used. To better understand it, try this: >>>4 >>>_ >>>_*_;_*_;_/4

See what I mean?

Comments