Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KimMinSeob
Python
Commits
be4d7448
Commit
be4d7448
authored
6 years ago
by
KimMinSeob
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
a624ae81
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
딕셔너리 연습.py
+116
-0
116 additions, 0 deletions
딕셔너리 연습.py
with
116 additions
and
0 deletions
딕셔너리 연습.py
0 → 100644
+
116
−
0
View file @
be4d7448
Python
3.7
.
1
(
v3
.
7.1
:
260
ec2c36a
,
Oct
20
2018
,
03
:
13
:
28
)
[
Clang
6.0
(
clang
-
600.0
.
57
)]
on
darwin
Type
"
help
"
,
"
copyright
"
,
"
credits
"
or
"
license()
"
for
more
information
.
>>>
#딕셔너리 자료형
>>>
dic
=
{
'
name
'
:
'
kim
'
,
'
phone
'
:
'
01000000000
'
,
'
birth
'
:
'
1995
'
}
>>>
dic
[
1
]
Traceback
(
most
recent
call
last
):
File
"
<pyshell#2>
"
,
line
1
,
in
<
module
>
dic
[
1
]
KeyError
:
1
>>>
dic
[
'
name
'
]
'
kim
'
>>>
a
=
{
1
:[
1
,
2
,
3
]}
>>>
a
{
1
:
[
1
,
2
,
3
]}
>>>
a
[
1
]
[
1
,
2
,
3
]
>>>
a
=
{
1
:
'
a
'
}
>>>
a
{
1
:
'
a
'
}
>>>
a
[
2
]
=
'
b
'
>>>
a
{
1
:
'
a
'
,
2
:
'
b
'
}
>>>
a
[
'
name
'
]
=
'
kim
'
>>>
a
{
1
:
'
a
'
,
2
:
'
b
'
,
'
name
'
:
'
kim
'
}
>>>
a
[
3
]
=
[
1
,
2
,
3
]
>>>
a
{
1
:
'
a
'
,
2
:
'
b
'
,
'
name
'
:
'
kim
'
,
3
:
[
1
,
2
,
3
]}
>>>
del
a
[
'
name
'
]
>>>
a
{
1
:
'
a
'
,
2
:
'
b
'
,
3
:
[
1
,
2
,
3
]}
>>>
del
a
[
3
]
>>>
a
{
1
:
'
a
'
,
2
:
'
b
'
}
>>>
#딕셔너리는 튜플과 리스트처럼 인덱싱 할 수없다.
>>>
a
[
1
]
'
a
'
>>>
#딕셔너리에서 a[1]은 2번째 인덱스의 값을 부르는것이 아니라 key값이 1인 것의 value를 의미
>>>
a
[
'
a
'
]
Traceback
(
most
recent
call
last
):
File
"
<pyshell#22>
"
,
line
1
,
in
<
module
>
a
[
'
a
'
]
KeyError
:
'
a
'
>>>
a
=
{
'
a
'
:
1
,
'
b
'
:
2
}
>>>
a
[
'
a
'
]
1
>>>
#딕셔너리에서 key 값은 중복되면 안된다.
>>>
a
=
{
1
:
'
a
'
,
1
:
'
b
'
}
>>>
a
{
1
:
'
b
'
}
>>>
#key값으로 리스트는 안되고 튜플은된다.
>>>
a
=
{[
1
,
2
]:
'
a
'
,
2
:
'
b
'
}
Traceback
(
most
recent
call
last
):
File
"
<pyshell#29>
"
,
line
1
,
in
<
module
>
a
=
{[
1
,
2
]:
'
a
'
,
2
:
'
b
'
}
TypeError
:
unhashable
type
:
'
list
'
>>>
a
=
{(
1
,
2
):
'
a
'
,
2
:
'
b
'
}
>>>
a
[(
1
,
2
)]
'
a
'
>>>
#딕셔너리 관련 함수들
>>>
a
=
{
'
name
'
:
'
kim
'
,
'
phone
'
:
'
01050010000
'
,
'
birth
'
:
'
1995
'
}
>>>
a
.
keys
()
dict_keys
([
'
name
'
,
'
phone
'
,
'
birth
'
])
>>>
for
i
in
a
.
keys
()
SyntaxError
:
invalid
syntax
>>>
for
i
in
a
.
keys
():
print
(
i
)
name
phone
birth
>>>
a
.
values
()
dict_values
([
'
kim
'
,
'
01050010000
'
,
'
1995
'
])
>>>
a
.
items
()
dict_items
([(
'
name
'
,
'
kim
'
),
(
'
phone
'
,
'
01050010000
'
),
(
'
birth
'
,
'
1995
'
)])
>>>
a
.
clear
()
>>>
a
{}
>>>
a
=
{
'
name
'
:
'
kim
'
,
'
phone
'
:
'
01050010000
'
,
'
birth
'
:
'
1995
'
}
>>>
'
name
'
in
a
True
>>>
'
ne
'
in
a
False
>>>
#연습문제 딕셔너리 만들기
>>>
a
=
{
'
name
'
:
'
honggildong
'
,
'
birth
'
:
'
1128
'
,
'
age
'
:
'
30
'
}
>>>
a
{
'
name
'
:
'
honggildong
'
,
'
birth
'
:
'
1128
'
,
'
age
'
:
'
30
'
}
>>>
#추출
>>>
a
=
{
'
a
'
:
90
,
'
b
'
:
90
,
'
c
'
:
70
}
>>>
a
[
'
b
'
]
90
>>>
del
a
[
'
b
'
]
>>>
a
{
'
a
'
:
90
,
'
c
'
:
70
}
>>>
a
.[
'
b
'
]
SyntaxError
:
invalid
syntax
>>>
a
[
'
b
'
]
Traceback
(
most
recent
call
last
):
File
"
<pyshell#55>
"
,
line
1
,
in
<
module
>
a
[
'
b
'
]
KeyError
:
'
b
'
>>>
a
.
get
(
'
b
'
:
70
)
SyntaxError
:
invalid
syntax
>>>
a
.
get
(
'
b
'
/
70
)
Traceback
(
most
recent
call
last
):
File
"
<pyshell#57>
"
,
line
1
,
in
<
module
>
a
.
get
(
'
b
'
/
70
)
TypeError
:
unsupported
operand
type
(
s
)
for
/
:
'
str
'
and
'
int
'
>>>
a
.
get
(
'
b
'
/
'
70
'
)
Traceback
(
most
recent
call
last
):
File
"
<pyshell#58>
"
,
line
1
,
in
<
module
>
a
.
get
(
'
b
'
/
'
70
'
)
TypeError
:
unsupported
operand
type
(
s
)
for
/
:
'
str
'
and
'
str
'
>>>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment