Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson12-2
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
eb5a27bc
authored
Oct 26, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
59f687ca
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
0 deletions
diy2.py
yyy.py
diy2.py
0 → 100644
View file @
eb5a27bc
# file=open(r'c:\Users\Administrator\Desktop\book.txt','w',encoding='utf-8')
# file.write("小兰:12本\n") # XIAO LAN BEN
# file.write("小丽:11本\n") # LI
# file.write("李文:9本\n") # LI WEN
# file.write("张伟:16本\n") # ZHANG WEI
# file.close()
with
open
(
r'c:\Users\Administrator\Desktop\book.txt'
,
'w'
,
encoding
=
'utf-8'
)
as
file
:
file
.
write
(
"小强:12本
\n
"
)
# XIAO QIANG BEN
file
.
write
(
"李明:12本
\n
"
)
# LI MING
# with open(r'c:\Users\Administrator\Desktop\book.txt','r',encoding='utf-8') as file:
# a=file.read()
# print(a)
with
open
(
r'c:\Users\Administrator\Desktop\book.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
for
data
in
file
:
if
"小强:12本"
in
data
:
print
(
"数据在文件中"
)
# SHU JU ZAI WEN JIAN ZHONG
\ No newline at end of file
yyy.py
0 → 100644
View file @
eb5a27bc
# 修改文件中的内容:序列名.replace(旧,新)
str
=
"我有一个苹果"
print
(
str
.
replace
(
"一"
,
"三"
))
new_data
+=
data
new_data
=
new_data
+
data
i
=
i
+
1
i
+=
1
\ 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