Python中join和split用法實例
join用來連接字符串,split恰好相反,拆分字符串的。
不用多解釋,看完代碼,其意自現(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)文章
Python創(chuàng)建一個自定義視頻播放器的實現(xiàn)
本文主要介紹了Python創(chuàng)建一個自定義視頻播放器的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02python實現(xiàn)Thrift服務(wù)端的方法
這篇文章主要介紹了python實現(xiàn)Thrift服務(wù)端的方法,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下2021-04-04Python數(shù)據(jù)結(jié)構(gòu)與算法(幾種排序)小結(jié)
這篇文章主要介紹了Python數(shù)據(jù)結(jié)構(gòu)與算法(幾種排序)的相關(guān)知識,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-06-06