diff --git a/ LectureNote - list,tuple, dict.py b/ LectureNote - list,tuple, dict.py new file mode 100644 index 0000000000000000000000000000000000000000..5512481a0056bdb9458ed79040fd3e28b0abf6b1 --- /dev/null +++ b/ LectureNote - list,tuple, dict.py @@ -0,0 +1,171 @@ +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. +>>> #리스트, 튜플, 딕셔너리 +>>> a=['oop','python','java'] +>>> a +['oop', 'python', 'java'] +>>> a[0] +'oop' +>>> a[1] +'python' +>>> a[2] +'java' +>>> a[3] +Traceback (most recent call last): + File "<pyshell#6>", line 1, in <module> + a[3] +IndexError: list index out of range +>>> b=[1,2,3,4,] +>>> b +[1, 2, 3, 4] +>>> c=[1,2,3,4,5,6,7,8,9] +>>> c[0:3] +[1, 2, 3] +>>> c[4:7} +SyntaxError: invalid syntax +>>> c[5:8] +[6, 7, 8] +>>> c[:7] +[1, 2, 3, 4, 5, 6, 7] +>>> a=[1,2,3,4] +>>> b=[5,6,7,8] +>>> a+b +[1, 2, 3, 4, 5, 6, 7, 8] +>>> a[2]=10 +>>> a +[1, 2, 10, 4] +>>> a[3]=0 +>>> a +[1, 2, 10, 0] +>>> len(a) +4 +>>> a.append(50) +>>> a +[1, 2, 10, 0, 50] +>>> a.extend([0,2,4,8]) +>>> a +[1, 2, 10, 0, 50, 0, 2, 4, 8] +>>> a.insert(3,500) +>>> a +[1, 2, 10, 500, 0, 50, 0, 2, 4, 8] +>>> a.insert(1,100) +>>> a +[1, 100, 2, 10, 500, 0, 50, 0, 2, 4, 8] +>>> a.remove(2) +>>> a +[1, 100, 10, 500, 0, 50, 0, 2, 4, 8] +>>> a.remove(2) +>>> a +[1, 100, 10, 500, 0, 50, 0, 4, 8] +>>> a.pop(4) +0 +>>> a +[1, 100, 10, 500, 50, 0, 4, 8] +>>> a.index(10) +2 +>>> a.index(10000) +Traceback (most recent call last): + File "<pyshell#37>", line 1, in <module> + a.index(10000) +ValueError: 10000 is not in list +>>> a.append(1) +>>> a.append(1) +>>> a +[1, 100, 10, 500, 50, 0, 4, 8, 1, 1] +>>> a.count(1) +3 +>>> a.sort() +>>> a +[0, 1, 1, 1, 4, 8, 10, 50, 100, 500] +>>> a.sort(reverse=true) +Traceback (most recent call last): + File "<pyshell#44>", line 1, in <module> + a.sort(reverse=true) +NameError: name 'true' is not defined +>>> a.sort(reverse=True) +>>> a +[500, 100, 50, 10, 8, 4, 1, 1, 1, 0] +>>> a.reverse +<built-in method reverse of list object at 0x112353448> +>>> a.reverse() +>>> a +[0, 1, 1, 1, 4, 8, 10, 50, 100, 500] +>>> a=(1,2,3) +>>> type(a) +<class 'tuple'> +>>> a +(1, 2, 3) +>>> a=1,2,3,4, +>>> a +(1, 2, 3, 4) +>>> type(a) +<class 'tuple'> +>>> a=(1,) +>>> type(a) +<class 'tuple'> +>>> a=(1) +>>> type(a) +<class 'int'> +>>> #요소가 한개일때 콤마 찍어줘야 하는 이유 +>>> b=1, +>>> type(b) +<class 'tuple'> +>>> b +(1,) +>>> a=(1,2,3,4) +>>> a[0] +1 +>>> a[1] +2 +>>> a[2] +3 +>>> a[3] +4 +>>> a[1] = 5 +Traceback (most recent call last): + File "<pyshell#69>", line 1, in <module> + a[1] = 5 +TypeError: 'tuple' object does not support item assignment +>>> len(a) +4 +>>> one,two,three,four = a +>>> a +(1, 2, 3, 4) +>>> one +1 +>>> two +2 +>>> three +3 +>>> four +4 +>>> one,two,three = a +Traceback (most recent call last): + File "<pyshell#77>", line 1, in <module> + one,two,three = a +ValueError: too many values to unpack (expected 3) +>>> dic = {} +>>> dic['python'] = 'www.pthon.org' +>>> dic['microsoft'] = 'www.microsoft.com' +>>> dic['apple'] = 'www.apple.com' +>>> dic['phthon'] +Traceback (most recent call last): + File "<pyshell#82>", line 1, in <module> + dic['phthon'] +KeyError: 'phthon' +>>> dic['python'] +'www.pthon.org' +>>> dic['microsoft'] +'www.microsoft.com' +>>> type(dic) +<class 'dict'> +>>> dic +{'python': 'www.pthon.org', 'microsoft': 'www.microsoft.com', 'apple': 'www.apple.com'} +>>> dic.keys() +dict_keys(['python', 'microsoft', 'apple']) +>>> dic.values() +dict_values(['www.pthon.org', 'www.microsoft.com', 'www.apple.com']) +>>> dic.items() +dict_items([('python', 'www.pthon.org'), ('microsoft', 'www.microsoft.com'), ('apple', 'www.apple.com')]) +>>>