Python3 split()方法


Python3 split()方法

split()通過指定分隔符對字符串進行切片,如果參數num 有指定值,則僅分隔 num 個子字符串

split()方法語法:str.split(str="", num=string.count(str))

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

num -- 分割次數。
#!/usr/bin/python3

str = "this is string example....wow!!!"
print (str.split( ))
print (str.split('i',1))
print (str.split('w'))

 

以上實例輸出結果如下:

['this', 'is', 'string', 'example....wow!!!'] ['th', 's is string example....wow!!!'] ['this is string example....', 'o', '!!!']

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM