美文网首页python编程
python中的split方法的用法

python中的split方法的用法

作者: 安琪儿2018 | 来源:发表于2019-08-03 11:17 被阅读0次

Python split() 通过指定分隔符对字符串进行切片,如果参数 num 有指定值,则分隔 num+1 个子字符串

语法

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

参数

str -- 分隔符,默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等。

num -- 分割次数。默认为 -1, 即分隔所有。

返回值

返回分割后的字符串列表。

实例

ten_things = "apples oranges crows telephone light sugar"

stuff = ten_things.split(' ', len(ten_things) )

print(stuff)

打印:['apples', 'oranges', 'crows', 'telephone', 'light', 'sugar']

相关文章

网友评论

    本文标题:python中的split方法的用法

    本文链接:https://www.haomeiwen.com/subject/gfqjdctx.html