首页 > 其他分享 >9.7 字符串的常用操作_替换与合并

9.7 字符串的常用操作_替换与合并

时间:2022-09-04 12:25:34浏览次数:58  
标签:java Python hello print 字符串 9.7 替换

 

s='hello,Python,Python,Python'
print('用字符串替换其中字符串,替换2次',s.replace('Python','java',2))

lst=['hello','java','Python']  #可以是列表或者元组
print('用空格连接列表全部元素',''.join(lst))
print('用*连接列表全部元素','*'.join(lst))

'''如果是字符串'''
print('如果为字符串时,作为字符串序列插入','*'.join('Python'))
用字符串替换其中字符串,替换2次 hello,java,java,Python
用空格连接列表全部元素 hellojavaPython
用*连接列表全部元素 hello*java*Python
如果为字符串时,作为字符串序列插入 P*y*t*h*o*n

 

标签:java,Python,hello,print,字符串,9.7,替换
From: https://www.cnblogs.com/988MQ/p/16654815.html

相关文章