Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中的省略号混淆_Python_Python 3.x_List_Ipython Notebook_Ellipsis - Fatal编程技术网

Python中的省略号混淆

Python中的省略号混淆,python,python-3.x,list,ipython-notebook,ellipsis,Python,Python 3.x,List,Ipython Notebook,Ellipsis,为什么当省略出现在列表中时,它们并不相等,而当它们单独出现时,它们是相等的?检查一下 In [81]: a Out[81]: [[...]] In [82]: b Out[82]: [[Ellipsis]] In [83]: a==b Out[83]: False In [84]: ...==Ellipsis Out[84]: True 但是 >a=[] >>>a.附加(a) >>>a [] >>>印刷品(a) [[...]] >>>a==[[省略号]] 假的 >>> 这是预期的,因

为什么当省略出现在列表中时,它们并不相等,而当它们单独出现时,它们是相等的?

检查一下

In [81]: a
Out[81]: [[...]]

In [82]: b
Out[82]: [[Ellipsis]]

In [83]: a==b
Out[83]: False

In [84]: ...==Ellipsis
Out[84]: True
但是

>a=[]
>>>a.附加(a)
>>>a
[]
>>>印刷品(a)
[[...]]
>>>a==[[省略号]]
假的
>>> 

这是预期的,因为您正在将
省略号
对象与递归定义列表的省略号表示形式进行比较。

[[…]]==[[省略号]]
为真。这可能是因为
a
问题
..
因为表示。您是如何创建
a
b
a
是这样创建的:
a=[1];a[0]=a
b
是这样创建的:
b=[[省略号]]
>>> [[...]] == [[Ellipsis]]
True
>>> a = []
>>> a.append(a)
>>> a
[<Recursion on list with id=70796424>]
>>> print(a)
[[...]]
>>> a==[[Ellipsis]]
False
>>>