为了账号安全,请及时绑定邮箱和手机立即绑定

针对Python这道题有个疑问!

针对Python这道题有个疑问!

asdhjhg 2017-03-06 15:06:15
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又可以正常执行,小白求解释啊
查看完整描述

1 回答

?
weibo_许1un_0

TA贡献3条经验 获得超0个赞

none 0 布尔值位false 大于0为true none是<0的,加了>0的条件自然不会显示。 原因报错都写了
查看完整回答
反对 回复 2017-03-06
  • 1 回答
  • 0 关注
  • 1203 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信