国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python中join和split用法實例

2020-02-23 00:42:45
字體:
來源:轉載
供稿:網友

join用來連接字符串,split恰好相反,拆分字符串的。
不用多解釋,看完代碼,其意自現了。
代碼如下:
>>>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.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安宁市| 安多县| 双城市| 锡林浩特市| 和政县| 图木舒克市| 上虞市| 临泉县| 若羌县| 东源县| 金门县| 岚皋县| 巴彦县| 耿马| 巴林右旗| 水城县| 汉沽区| 仙游县| 和龙市| 垣曲县| 光山县| 永顺县| 铁岭市| 积石山| 大城县| 房产| 启东市| 三台县| 永寿县| 娱乐| 新营市| 延吉市| 兰溪市| 高邑县| 翼城县| 大兴区| 桑植县| 阿巴嘎旗| 静海县| 鄂托克旗| 北流市|