diff --git "a/\341\204\203\341\205\265\341\206\250\341\204\211\341\205\247\341\204\202\341\205\245\341\204\205\341\205\265 \341\204\213\341\205\247\341\206\253\341\204\211\341\205\263\341\206\270.py" "b/\341\204\203\341\205\265\341\206\250\341\204\211\341\205\247\341\204\202\341\205\245\341\204\205\341\205\265 \341\204\213\341\205\247\341\206\253\341\204\211\341\205\263\341\206\270.py" new file mode 100644 index 0000000000000000000000000000000000000000..24c7ce531c71dc91735b72ebbd28d629f21b2b66 --- /dev/null +++ "b/\341\204\203\341\205\265\341\206\250\341\204\211\341\205\247\341\204\202\341\205\245\341\204\205\341\205\265 \341\204\213\341\205\247\341\206\253\341\204\211\341\205\263\341\206\270.py" @@ -0,0 +1,116 @@ +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' +>>>