1

Ok I have something for you guys, i type this code in fresh new python terminal:

>>> print _
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '_' is not defined
>>> 'magic'[::2]
'mgc'
>>> print _
mgc
>>> 'magic'[::-1]
'cigam'
>>> print _
cigam

or:

>>> def foo(x):
...     return x * x
... 
>>> print _
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '_' is not defined
>>> foo(3)
9
>>> print _
9

Is this normal python behavior?

k.rozycki
  • 635
  • 1
  • 5
  • 12
  • What do you mean *"how is this possible*"? – jonrsharpe Jul 12 '14 at 19:14
  • Well, I think he wonders why accessing `_` the second time doesn't raise a `NameError` again, even though he didn't define it in the meantime - which is a fairly legitimate question I think, unless you know about this feature :) – Lukas Graf Jul 12 '14 at 19:16

0 Answers0