Python一个字符串删除另一字符串包含的所有字符

用python语言,直接使用列表的方式,将两个字符串利用while循环放进列表中,然后使用replace将字符串1中包含的所有字符串2的字符全部删除,再用for循环输出

str_font = input("please inout first string :")
str_behind = input("please input second string :")
font = []
behind = []
str_font_length = 0
for k in str_font:
    str_font_length += 1
str_behind_length = 0
for j in str_behind:
    str_behind_length += 1
i = 0
while i < str_font_length:
    font.append(str_font[i:i+1])
    i+=1

j = 0
while j < str_behind_length:
    behind.append(str_behind[j:j+1])
    j += 1
q = 0
print(str_behind_length)
print(font[4])
while q < str_font_length:
    if font[q] in behind:
        font[q] = ""
    q += 1
print(q)
for i in font:
    print(i,end="")

运行结果如图所示:
运行结果

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值