Discuss / Python / 为什么我的会报错??一直没懂 求指导

为什么我的会报错??一直没懂 求指导

Topic source

L1 = ['Hello', 'World', 18, 'Apple', None] L2 = [s.lower() for s in L1 if isinstance(s,str) is True] print(L2)

报错: TypeError: isinstance() arg 2 must be a type or tuple of types

isinstance(s,str) 就已经输出一个结果啦,is True是多余的,你要不报错可以加上括号, L2 = [s.lower() for s in L1 if (isinstance(s,str) is True)]


  • 1

Reply