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
132af008
authored
Feb 11, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
a8dc8308
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletions
diy.py
diy.py
View file @
132af008
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'"""项目介绍:整理数据
#提示1: split()方法
#用法: str.split(str=")
#参数: str是分隔符,默认为所有的空字符,包括:
#空格、换行(n)等。
#作用:通过指定分隔符对字符串进行切片,返回分割后的字符串列表。
#这里是按照空格来分割所有的字符串,因此括号中可以什么都不写,是用默认参数。
#提示2:列表索引与切片
#姓名在第一-列,索引是从0开始数的,因此姓名
#可以用data[0]表示;义卖款就是后面的,即[1:]。
with
open
(
r'C:\Users\1\Desktop\1.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
a
=
file
.
readlines
for
i
in
a
:
data
=
i
.
split
print
(
data
[
0
])
print
(
data
[
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