In interactive mode, the last printed expression is assigned to the
variable _
. This means that when you are using Python as a
desk calculator, it is somewhat easier to continue calculations, for
example:
>>> tax = 17.5 / 100 >>> price = 3.50 >>> price * tax 0.6125 >>> price + _ 4.1125 >>> round(_, 2) 4.11 >>>
For reasons too embarrassing to explain, this variable is implemented
as a built-in (living in the module __builtin__
), so it should
be treated as read-only by the user. I.e. don't explicitly assign a
value to it -- you would create an independent local variable with
the same name masking the built-in variable with its magic behavior.