Python-cut-join

s = 'I  love you more than I can say'
# 按照指定的内容进行切割, 返回一个列表
# sep:指定按照什么内容进行切割
# maxsplit:指定切割次数
# ret = s.split(' ', maxsplit=1)
# ret = s.split()
# 从右边开始切割
ret = s.rsplit(' ', maxsplit=1)
print(ret)

s = 'Hello\nworld'
# 安照换行进行切割
print(s.splitlines())

s = 'I love you more than I can say'
ret = s.split()
# 字符串的拼接
s2 = '*'.join(ret)
print(s2)

猜你喜欢

转载自blog.csdn.net/huaxiawudi/article/details/81165528
cut
今日推荐