每天一点python——day68

#每天一点Python——68
#字符串的替换与合并
#如图:

#①字符串的替换
s='hello,computer'#创建一个字符串
print(s.replace('computer','python'))
#用python替换computer
'''
替换语法
string.replace(old, new, count)
sring:表示字符串
old:要被替换的旧字符串。
new:替换后的新字符串。
count:可选参数,指定最多替换的次数。
'''
a="Hello, World!"
new_s = a.replace("o", "x", 2,)
print(new_s)
s1='hello,computer,computer,computer'
print(s1.replace('computer','python',2))
#②字符串的合并
'''
分隔符或连接符.join(字符串序列)
'''
#列表
list1=['ab','bc','vl']
print('|'.join(list1))
print(''.join(list1))#‘’里面什么也不输入,直接合并
#元组
yz=('hello','world','nihao')
print(''.join(yz))#直接拼接
#在一个字符串里面直接输入+,意思为直接把字符串作为字符串序列并在每一个字符里面加上+
print('+'.join('python'))
#输出结果为p+y+t+h+o+n

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值