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="")

运行结果如图所示:
Python一个字符串删除另一字符串包含的所有字符_第1张图片

你可能感兴趣的:(Python一个字符串删除另一字符串包含的所有字符)