Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson9_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
7fd3003d
authored
Jul 08, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
5ab88987
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletions
demo.py
diy2.py
demo.py
0 → 100644
View file @
7fd3003d
x
=
5
if
x
%
2
==
0
:
print
(
"偶数"
)
else
:
print
(
"奇数"
)
\ No newline at end of file
diy2.py
View file @
7fd3003d
score
=
{
'语文'
:
91
,
'数学'
:
88
,
'英语'
:
85
}
# 请对字典进行遍历,将保存的分数以键值对的形式提取打印出来
st
=
{
"张三"
:
score
,
"李四"
:
socre
,
"王五"
:
score
}
# 字典中嵌套了字典
# 按键遍历字典
print
(
"**一、直接用字典名字**"
)
print
(
" **1、直接用字典名字**"
)
for
i
in
score
:
# 一直接用字典名字
print
(
i
)
print
(
" **2、用字典的keys方法**"
)
for
i
in
score
.
keys
():
# 二用字典的keys方法
print
(
i
)
print
(
"**二、按值遍历字典**"
)
for
i
in
score
.
values
():
print
(
i
)
print
(
"**三、按键值对遍历字典**"
)
for
k
,
v
in
score
.
items
():
print
(
k
,
v
)
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