#Python TQC考題905 字串資料刪除,datanew=data.replace(strold,strnew), f.write(datanew)
“””
txt檔內容如下:
Apple Kiwi Banana
Tomato Pear Durian
要將Tomato刪除
.replace(“Tomato”,””)
將Tomato換成什麼都沒有
“””
f_name = input()
string = input()
# TODO
with open(f_name,”r+”,encoding=”utf-8″) as file:
print(“=== Before the deletion”)
# TODO
data=file.read()
print(data)
print(“=== After the deletion”)
# TODO
dataNew = data.replace(string,””)
print(dataNew)
file.seek(0,0)
file.write(dataNew)
近期留言