廖雪峰Python教程疑问
2016-08-25 09:06
344 查看
1. 字符串的strip()方法
原文:
“把一个序列中的空字符串删掉,可以这么写:
疑问:如果改为,
就会提示错误,AttributeError: 'Nonetype' object has no attribute 'strip'
不知道 s and s.strip() 与 s.strip()的区别在哪里。
出处:http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001431821084171d2e0f22e7cc24305ae03aa0214d0ef29000
原文:
“把一个序列中的空字符串删掉,可以这么写:
def not_empty(s):
return s and s.strip()
list(filter(not_empty, ['A', '', 'B', None, 'C', ' ']))
# 结果: ['A', 'B', 'C']”
疑问:如果改为,
def not_empty(s):
return s.strip()
就会提示错误,AttributeError: 'Nonetype' object has no attribute 'strip'
不知道 s and s.strip() 与 s.strip()的区别在哪里。
出处:http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001431821084171d2e0f22e7cc24305ae03aa0214d0ef29000
相关文章推荐
- Python在线教程(廖雪峰)
- 廖雪峰的Python教程
- Python练习 - 廖雪峰教程
- [廖雪峰 - Python2.7教程] 返回函数 - 学习笔记
- 廖雪峰Python 3.X 教程
- python简明教程中__del__的疑问
- 【Python】|廖雪峰python 3教程#打印版# #完整版# #吐血整理#
- 据廖雪峰python3教程----python学习第十二天
- 据廖雪峰python3教程----python学习第十一天
- [廖雪峰 - Python2.7教程] 返回函数2 - 学习笔记
- 廖雪峰Python教程学习笔记
- 据廖雪峰python3教程----python学习第三天
- 据廖雪峰python3教程----python学习第二天
- 据廖雪峰python3教程----python学习第十三天
- 据廖雪峰python3教程----python学习第八天
- 廖雪峰的0Python教程
- 廖雪峰python教程
- 据廖雪峰python3教程----python学习第五天
- asyncio创建协程解析——分析廖雪峰的Python教程之创建WEB服务(转)
- Python学习笔记- 廖雪峰教程【python 2】//为继续学习爬虫准备-02 [待完善]