刚开始学习python ,学习了str的一些重要用法,按我自己理解分享给大家。

1, join(self, iterable)

#將字符串中的每一個元素按照指定分隔符進行拼接

test = "你像大海一样广阔"
#將字符串中的每一個元素按照指定分隔符進行拼接
print(test)
t = '_'
v = t.join(test)
#v = "_".join(test)
print(v)

 

 

2, split(self, sep)

#分隔字符串,不保留分隔符, sep 代表分到每几个分隔符

test = 'testasdsssffffdd'
v = test.split('s',3)
# v = test.partition('s')
print(v)

 

 

3, strip(self, chars=None)

# 去全部去空格

# 去掉左/t,/n ,/t,/n及全部去/t /n

# 移除指定字符,在willass 中搜索 wiaaaffffll,有就去掉

test = "willass"
v = test.strip("wiaaaffffll")
print(v)

 

posted on 2019-09-19 11:33  Will_Chu  阅读(402)  评论(0)    收藏  举报