Python TQC考題905 字串資料刪除,datanew=data.replace(strold,strnew), f.write(datanew)

加入好友
加入社群
Python TQC考題905 字串資料刪除,datanew=data.replace(strold,strnew), f.write(datanew) - 儲蓄保險王

#Python TQC考題905 字串資料刪除,datanew=data.replace(strold,strnew), f.write(datanew)

“””

跟TQC 906字串資料取代是姊妹題

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)

Python TQC考題905 字串資料刪除,datanew=data.replace(strold,strnew), f.write(datanew) - 儲蓄保險王

 

加入好友
加入社群
Python TQC考題905 字串資料刪除,datanew=data.replace(strold,strnew), f.write(datanew) - 儲蓄保險王

儲蓄保險王

儲蓄險是板主最喜愛的儲蓄工具,最喜愛的投資理財工具則是ETF,最喜愛的省錢工具則是信用卡

You may also like...

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *