Skip to content
Snippets Groups Projects
Commit be4d7448 authored by KimMinSeob's avatar KimMinSeob
Browse files

Upload New File

parent a624ae81
No related branches found
No related tags found
No related merge requests found
Python 3.7.1 (v3.7.1:260ec2c36a, 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'
>>>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment