有人可以就以下结果提供一些评论。当我写时,我对自己实际在做什么感到特别困惑: alist = [None]*5 in #1 以及为什么 'is' 语句是 False ,但 isinstance 在 #3 中是 True 非常感谢。
#1
>>> alist = [None]*5
>>> alist
[None, None, None, None, None]
>>> type(alist[0])
<type 'NoneType'>
>>> type(alist[0]) is None
False
#2
>>> alist = [int]*5
>>> alist
[<type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>]
>>> type(alist[0]) is int
False
>>> isinstance(alist[0],int)
False
#3
>>> alist = [0.0]*5
>>>type(alist[0])
<type 'float'>
>>> alist[0] is float
False
>>> isinstance(alist[0],float)
True