split() 注意事项.
2024-10-19 01:22:58
split():
当函数默认为空,它会把所有空格(空格符、制表符、换行符)当作分隔符.
但是当函数参数默认为其他,将会对 空格符、制表符、换行符 当作元素进行分割.
a = 'hello world!'
print a.split() a = 'hello world!' \
''
print a.split() a = 'hello world! ' \
''
print a.split(' ')
相对应的输出结果
['hello', 'world!']
['hello', 'world!']
['hello', 'world!', '']
第三个a中的换行符,被当作新元素进行了分割.
print a.split(' ') print filter(None, a.split(' '))
输出结果为:
['hello', 'world!']
filter(...)
filter(function or None, sequence) -> list, tuple, or string
Return those items of sequence for which function(item) is true. If
function is None, return the items that are true. If sequence is a tuple
or string, return the same type, else return a list.
注意绿字部分:
感谢博主.SZlibraco
原链接:
http://www.cnblogs.com/librasz/p/3232611.html
最新文章
- 序列化笔记之一:Google的Protocol Buffer格式分析
- 《C#微信开发系列(2)-自定义菜单管理》
- [BZOJ3142][HNOI2013]数列(组合)
- 用wcf实现带有“秒传”功能的网盘
- SQL Server 批量插入数据的两种方法(转)
- [HDOJ3974]Assign the task(建树胡搞)
- 和阿文一起学H5——H5工具、素材
- MS SQLserver数据库安装
- [Boost]图形处理库Boost::Polygon
- IOS的处理touch事件处理(按照手指的移动移动一个圆,开发环境用的ios7,storyboard)
- easyui&;8Jquery ztree树插件
- SSM-MyBatis-15:Mybatis中关联查询(多表操作)
- 《Java开发学习大纲文档》V6.0(已经不公布了,请查看第七版)
- rancher2.0部署
- SpringBoot+MyBatis多数据源使用分页插件PageHelper
- php的语法
- java常用设计模式九:桥接模式
- 20145304 Exp8 Web基础
- Python操作Rabbit MQ的5种模式
- IP addresses in C#