#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)







![Python TQC考題404 數字反轉判斷,n_rev=n[::-1], list1.reverse() Python TQC考題404 數字反轉判斷,n_rev=n[::-1], list1.reverse()](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2022/04/20220825152414_97.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



近期留言