その前にPythonと戯れてみるw

ちょっと(何故か)java-jaで話題になったので……


Pythonは「_(アンダースコア)」で直前の値が取得できます。
Perlで言うと$_に当たるのかな?*1
で、その「_」なんですが、予約語じゃないので上書きできちゃいます。
こんな感じ

Python 2.5.1 (r251:54863, Jul 11 2007, 16:37:33) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwinType 
"help", "copyright", "credits" or "license" for more information.
import rlcompleter, readline
>>> 1 + 2
3
>>> _
3
>>> _ = 0
>>> _
0
>>> 1 + 2
3
>>> _
0


さらに衝撃の事実として「True」も予約語ではないので……

Python 2.5.1 (r251:54863, Jul 11 2007, 16:37:33) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwinType 
"help", "copyright", "credits" or "license" for more information.
import rlcompleter, readline
>>> if True:
...   print 'true'
... else:
...   print 'false'
... 
true
>>> True = 0
>>> if True:
...   print 'true'
... else:
...   print 'false'
... 
false
>>> 

すごいですね!!
ぱいの神秘に触れた気がしました。
おっぱいマニア*2への道は神秘にあふれていますね!!


p.s.
ipython を使うとまた違った結果で
更にぱいの神秘に触れた気分です。

*1:Perlあまり詳しくないので間違えてたらごめんなさい

*2:Python使いの人