Python:在两者之间定义一个未知值的元组

时间:2013-06-12 08:35:23

标签: python python-2.7 tuples ipython

这是python中最有趣的事情我在变量引用中遇到了元组。 有人可以给我一个等价的C ???

h = 1,_,3,_

h
Out[2]: (1, '', 3, '')

 h = 1,'',3, ''

h
Out[5]: (1, '', 3, '')

这是怎么发生的? _和''相等吗?有什么区别?

我想知道有多少这样的神奇参考?

1 个答案:

答案 0 :(得分:3)

IPython shell中_的默认值为''

monty@xonix:~/py$ ipython --classic
Python 2.7.4 (default, Apr 19 2013, 18:32:33) 
Type "copyright", "credits" or "license" for more information.

IPython 0.13.2 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
>>> _
''
>>> 2*2
4
>>> _  # Now _ returns the value of last expression
4