Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson12-4
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e839e3a1
authored
Aug 05, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
b00e1dbf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
1.PY
1.PY
0 → 100644
View file @
e839e3a1
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment