Python 字符串

Python join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串。

s1 = "-"
s2 = ""
seq = ("r", "u", "n", "o", "o", "b") # 字符串序列
print (s1.join( seq ))
print (s2.join( seq ))

以上实例输出结果如下:

r-u-n-o-o-b
runoob
Python split()通过指定分隔符对字符串进行切片,如果参数 num 有指定值,则仅分隔 num+1 个子字符串
str = "this is string example....wow!!!"
print (str.split( )) # 以空格为分隔符
print (str.split('i',1)) # 以 i 为分隔符
print (str.split('w')) # 以 w 为分隔符
['this', 'is', 'string', 'example....wow!!!']
['th', 's is string example....wow!!!']
['this is string example....', 'o', '!!!']
 
posted @ 2019-04-30 10:40  喵喵小学僧  阅读(179)  评论(0编辑  收藏  举报