Python笔记——string.split()

来源:互联网 发布:windows arp命令 编辑:程序博客网 时间:2024/05/22 12:15

参考网址:http://www.tutorialspoint.com/python/string_split.htm

函数描述:

     依子串即定界符str,将字符串string最多分裂为num+1个子串,返回列表。

语法:

     string.split(str=" ", num=string.count(str)).

参数

     str——定界符。默认为空格

     num——分裂的次数。默认的分裂次数为定界符在字符串中出现的次数,即可分裂的最大次数。关于count()方法可点击链接。

例子:

#!/usr/bin/pythonstr = "This is a string example"print str.split( )print str.split(' ', 2 )print str.split(' ', 2 )[0]

输出

['This', 'is', 'a', 'string', 'example']
['This', 'is', 'a string example']
This


0 0