print filter(lambda s:s and len(s.strip())>0, ['test', None, '', 'str', ' ', 'END'])
#正常输出['test', 'str', 'END']
print ‘ww ’.strip()
ww
print ' '.strip()
空
print filter(lambda s:s.strip(), ['test', None, '', 'str', ' ', 'END'])
# print filter(lambda s:s.strip(), ['test', None, '', 'str', ' ', 'END'])
AttributeError: 'NoneType' object has no attribute 'strip'
#是None在作祟,这是什么原因呢?而加上len(s.strip())>0又可以正常执行,小白求解释啊
添加回答
举报
0/150
提交
取消