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

最新文章

  1. 序列化笔记之一:Google的Protocol Buffer格式分析
  2. 《C#微信开发系列(2)-自定义菜单管理》
  3. [BZOJ3142][HNOI2013]数列(组合)
  4. 用wcf实现带有“秒传”功能的网盘
  5. SQL Server 批量插入数据的两种方法(转)
  6. [HDOJ3974]Assign the task(建树胡搞)
  7. 和阿文一起学H5——H5工具、素材
  8. MS SQLserver数据库安装
  9. [Boost]图形处理库Boost::Polygon
  10. IOS的处理touch事件处理(按照手指的移动移动一个圆,开发环境用的ios7,storyboard)
  11. easyui&8Jquery ztree树插件
  12. SSM-MyBatis-15:Mybatis中关联查询(多表操作)
  13. 《Java开发学习大纲文档》V6.0(已经不公布了,请查看第七版)
  14. rancher2.0部署
  15. SpringBoot+MyBatis多数据源使用分页插件PageHelper
  16. php的语法
  17. java常用设计模式九:桥接模式
  18. 20145304 Exp8 Web基础
  19. Python操作Rabbit MQ的5种模式
  20. IP addresses in C#

热门文章

  1. Lua 之面向对象编程
  2. python版本升级及pip部署方法
  3. Nginx负载均衡配置实例详解(转)
  4. DOS批处理中%cd%和%~dp0的区别
  5. VS Code 开发asp.net core 遇到的坑
  6. Linux里startup.sh 和 shutdown.sh
  7. 即将翻译 Building The New Financial Times Web App
  8. 网站为什么要做SEO
  9. [译]git fetch
  10. GridView控件隐藏列