Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson8-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
b782c3af
authored
Feb 27, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
dc865750
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
7 deletions
diy1.py
quiz.py
diy1.py
View file @
b782c3af
...
@@ -13,5 +13,4 @@ print(list_hero)
...
@@ -13,5 +13,4 @@ print(list_hero)
'''
'''
# 注释掉上面的代码,并创建一个名为dict_hero的字典
# 注释掉上面的代码,并创建一个名为dict_hero的字典
dict_hero
=
{
'猴三'
,
10
,
'猴一'
,
21
,
'猴五'
,
22
,
'猴队长'
,
29
,
'猴七'
,
30
}
dict_hero
=
{
'猴三'
,
10
,
'猴一'
,
21
,
'猴五'
,
22
,
'猴队长'
,
29
,
'猴七'
,
30
}
print
(
dict_hero
)
print
(
dict_hero
)
quiz.py
View file @
b782c3af
# 直接运行以下代码,说说你的发现:
#利用字典
list_hero
=
[
'赵一'
,
30
,
'丁二'
,
37
,
'孙五'
,
52
,
'王猛'
,
89
,
'周亮'
,
98
]
dict_hero
=
{
'赵一'
:
30
,
'丁二'
:
37
,
'孙五'
:
52
,
'王猛'
:
89
,
'周亮'
:
98
}
#xxx{"x",x}字典固定格式
dict_hero
=
{
'赵一'
:
30
,
'丁二'
:
37
,
'孙五'
:
52
,
'王猛'
:
89
,
'周亮'
:
98
}
print
(
dict_hero
[
"周亮"
])
#用键提取
print
(
len
(
list_hero
))
dict_hero
[
"周亮"
]
=
100
#用键替换
print
(
len
(
dict_hero
))
print
(
dict_hero
[
"周亮"
])
\ No newline at end of file
\ 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