Python中join和split用法實(shí)例
join用來(lái)連接字符串,split恰好相反,拆分字符串的。
不用多解釋?zhuān)赐甏a,其意自現(xiàn)了。
>>>li = ['my','name','is','bob']
>>>' '.join(li)
'my name is bob'
>>>s = '_'.join(li)
>>>s
'my_name_is_bob'
>>>s.split('_')
['my', 'name', 'is', 'bob']
其join和split的英文版解釋如下:
join(...)
S.join(sequence) -> string
Return a string which is the concatenation of the strings in the
sequence. The separator between elements is S.
split(...)
S.split([sep [,maxsplit]]) -> list of strings
Return a list of the words in the string S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are removed
from the result.
相關(guān)文章
PyCharm控制臺(tái)堆棧亂碼問(wèn)題解決方案
PyCharm環(huán)境都已經(jīng)配置成了UTF-8編碼,控制臺(tái)打印中文也不會(huì)出現(xiàn)亂碼,但報(bào)錯(cuò)堆棧信息中如果有中文會(huì)出現(xiàn)中文亂碼,遇到這樣的問(wèn)題如何解決呢,下面小編給大家?guī)?lái)了PyCharm控制臺(tái)堆棧亂碼問(wèn)題解決方案,感興趣的朋友一起看看吧2023-12-12Python創(chuàng)建一個(gè)自定義視頻播放器的實(shí)現(xiàn)
本文主要介紹了Python創(chuàng)建一個(gè)自定義視頻播放器的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02python實(shí)現(xiàn)Thrift服務(wù)端的方法
這篇文章主要介紹了python實(shí)現(xiàn)Thrift服務(wù)端的方法,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下2021-04-04一文講解如何查看python腳本所依賴(lài)三方包及其版本
Python因?yàn)榫哂谐嗟牡谌綆?kù)而被大家喜歡,下面這篇文章主要給大家介紹了關(guān)于如何查看python腳本所依賴(lài)三方包及其版本的相關(guān)資料,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下2023-03-03Python數(shù)據(jù)結(jié)構(gòu)與算法(幾種排序)小結(jié)
這篇文章主要介紹了Python數(shù)據(jù)結(jié)構(gòu)與算法(幾種排序)的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-06-06