Python 断言错误:[101120313651137,8601,1174835,1104,11411292119,102,0,0,0,0,0,0]不是

Python 断言错误:[101120313651137,8601,1174835,1104,11411292119,102,0,0,0,0,0,0]不是,python,assert,Python,Assert,即使预处理函数返回列表,每次都会引发断言错误 pre = n.preprocess("New York or Mumbai, choose of one these.") j = [] for i in range(4): ##To check the data type print("preprocess", type(pre[i])) self.assertIs(pre[i], list) 如何解决此错误?来自: 如果不指定pre[

即使预处理函数返回列表,每次都会引发断言错误

pre = n.preprocess("New York or Mumbai, choose of one these.")
j = []
for i in range(4):
   ##To check the data type
   print("preprocess", type(pre[i]))
   self.assertIs(pre[i], list)
如何解决此错误?

来自:

如果不指定pre[i]=list或类似的东西,那么变量pre[i]和内置数据类型list当然不是相同的对象。您应该使用其他方法进行比较,例如, .

为什么按标识断言?您是否试图断言pre[i]是list的一个实例?请参见.idlist vs id[1,2,3],这不是同一件事是的,我试图将pre[I]断言为list的一个实例。我不是通过身份断言,而是将pre作为列表的元组。
assertIs(first, second, msg=None)
assertIsNot(first, second, msg=None)
Test that first and second are (or are not) the same object.