[pyar] Curiosidad ++

Martin Cerdeira martincerdeira en gmail.com
Sab Oct 22 16:43:16 ART 2011


Hola, les vengo a dejar una "curiosidad" (por lo menos yo no lo
conocía) y, un lindo link (donde, estaba la curiosidad entre otras
cosas) Enjoy! =)

Link: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html

Curiosidad:

Interactive "_"

This is a really useful feature that surprisingly few people know.

In the interactive interpreter, whenever you evaluate an expression or
call a function, the result is bound to a temporary name, _ (an
underscore):

>>> 1 + 1
2
>>> _
2

_ stores the last printed expression.

When a result is None, nothing is printed, so _ doesn't change. That's
convenient!

This only works in the interactive interpreter, not within a module.

It is especially useful when you're working out a problem
interactively, and you want to store the result for a later step:

>>> import math
>>> math.pi / 3
1.0471975511965976
>>> angle = _
>>> math.cos(angle)
0.50000000000000011
>>> _
0.50000000000000011

-------------------------------------
Martín Cerdeira - Software Developer
[web] http://www.codmacs.blogspot.com/
()  ascii ribbon campaign
/\  www.asciiribbon.org



More information about the pyar mailing list