L = ['Hello', 'World', 18, 'Apple', None] L1=[s.lower() for s in L if isinstance(s, str) is True]#不加 is True 也是可以的,不知道为什么?换成is false就不行了 print(L1)
因为 不是 字符串 调用lower 方法, 会报错
因为if True和if True == True效果是一样的,换成False就恰好相反了了
Sign in to make a reply
用户5186439079
L = ['Hello', 'World', 18, 'Apple', None] L1=[s.lower() for s in L if isinstance(s, str) is True]#不加 is True 也是可以的,不知道为什么?换成is false就不行了 print(L1)