Commit e839e3a1 by BellCodeEditor

auto save

parent b00e1dbf
Showing with 22 additions and 0 deletions
new_data=''
with open(r'C:\Users\Administrator\Desktop\book.txt','a',encoding='utf-8') as file:
for data in filel:
if '小强:10本'in data
data=data.replace('小强:10本','小强:11本')
if '小兰:12本'in data
data=data.replace('小兰:12本','小兰:14本')
"""项目介绍:修改数据
修改小强的数据为11本,以及小兰的数据小兰:
12本修改为14本,可不要忘记写入哦,最后读取修改后的数据。
别忘了注释掉前一环节的代码哦
提示1:修改数据
str.replace(old, new)
old:旧字符串new:新字符串
提示2:写入数据
写入数据最重要的两点就是w只写模式和文件名.write()
提示3:读取数据
读取数据最重要的两点就是r只读模式和文件名.read(),别忘了有返回值,需要赋值给一个变
量哦
"""
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment