diff --git "a/\341\204\205\341\205\265\341\204\211\341\205\263\341\204\220\341\205\263\341\204\213\341\205\247\341\206\253\341\204\211\341\205\263\341\206\270.py" "b/\341\204\205\341\205\265\341\204\211\341\205\263\341\204\220\341\205\263\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..8809eb44343fc03304086d6ae020adbe0a6d2b94 --- /dev/null +++ "b/\341\204\205\341\205\265\341\204\211\341\205\263\341\204\220\341\205\263\341\204\213\341\205\247\341\206\253\341\204\211\341\205\263\341\206\270.py" @@ -0,0 +1,381 @@ +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. +>>> #리스트 +>>> odd = [1,3,5,7,9] +>>> odd +[1, 3, 5, 7, 9] +>>> type(odd) +<class 'list'> +>>> a=[] +>>> type(a) +<class 'list'> +>>> b=[1,2,3] +>>> c=['a','b','c'] +>>> d= +SyntaxError: invalid syntax +>>> d=[1,2,'life','is] + +SyntaxError: EOL while scanning string literal +>>> d=[1,2,'life','is'] + +>>> e=[1,2,['life','is']] + +>>> type(b) + +<class 'list'> +>>> type(c) + +<class 'list'> +>>> type(d) + +<class 'list'> +>>> type(e) + +<class 'list'> +>>> e[2] + +['life', 'is'] +>>> type[e[2]] + +Traceback (most recent call last): + File "<pyshell#17>", line 1, in <module> + type[e[2]] +TypeError: 'type' object is not subscriptable +>>> #리스트안에는 어떠한 자료형이 들어가든 상관없다. + +>>> a=[1,2,3] + +>>> a[1] + a[2] + +5 +>>> a[-1] + +3 +>>> #인덱스값이 -1이면 마지막값을 나타냄 + +>>> a=[1,2,3,['a','b','c']] + +>>> a[-1] + +['a', 'b', 'c'] +>>> a[3] + +['a', 'b', 'c'] +>>> a[3][0] + +'a' +>>> a[3][1] + +'b' +>>> a[3][2] + +'c' +>>> type(a[3]) + +<class 'list'> +>>> a=[1,2,3,4,5] + +>>> a[0:2] + +[1, 2] +>>> #a[x:y] >>> x이상 y미만인 인덱스에 있는 값들을 출력 + +>>> a=[1,2,3,['a','b','c'],4,5] + +>>> a[2:5] + +[3, ['a', 'b', 'c'], 4] +>>> a[3][:2] + +['a', 'b'] +>>> #리스트의 덧셈과 반복하기 + +>>> a=[1,2,3] + +>>> b=[4,5,6] + +>>> a+b + +[1, 2, 3, 4, 5, 6] +>>> a *3 + +[1, 2, 3, 1, 2, 3, 1, 2, 3] +>>> #덧셈을 할때는 자료형이 같아야한다. + +>>> a=[1,2,3] + +>>> a[2] + 'hi' + +Traceback (most recent call last): + File "<pyshell#43>", line 1, in <module> + a[2] + 'hi' +TypeError: unsupported operand type(s) for +: 'int' and 'str' +>>> str(a[2]) + + +SyntaxError: invalid syntax +>>> str[a[2]) + 'hi' + +SyntaxError: invalid syntax +>>> str(a[2]) + 'hi' + +'3hi' +>>> a=[1,2,3] + +>>> a[2] = 4 + +>>> a + +[1, 2, 4] +>>> #리스트는 위와같이 값 변경이 가능하다. + +>>> a[1:2] + +[2] +>>> a[1:2] = ['a,'b','c'] + +SyntaxError: invalid syntax +>>> a[1:2] = ['a','b','c'] + +>>> a + +[1, 'a', 'b', 'c', 4] +>>> a[1] = ['a','b','c'] + +>>> a + +[1, ['a', 'b', 'c'], 'b', 'c', 4] +>>> a[1:4] = 2 + +Traceback (most recent call last): + File "<pyshell#57>", line 1, in <module> + a[1:4] = 2 +TypeError: can only assign an iterable +>>> a[1:4] = [2] + +>>> a + +[1, 2, 4] +>>> #리스트 관련 함수들 + +>>> a=[1,2,3] + +>>> a.append(4) + +>>> a + +[1, 2, 3, 4] +>>> a.append([5,6]) + +>>> a + +[1, 2, 3, 4, [5, 6]] +>>> a=[1,5,4,2,3] + +>>> a.sort() + +>>> a + +[1, 2, 3, 4, 5] +>>> b=['a','e','c','d','b'] + +>>> b.sort() + +>>> b + +['a', 'b', 'c', 'd', 'e'] +>>> a.reverse() + +>>> b.reverse() + +>>> a + +[5, 4, 3, 2, 1] +b +>>> + +>>> b + +['e', 'd', 'c', 'b', 'a'] +>>> a.index(3) + +2 +>>> b.index('b') + +3 +>>> a=[1,2,3] + +>>> a.insert(0,4) + +>>> a + +[4, 1, 2, 3] +>>> a;insert(3,5) + +[4, 1, 2, 3] +Traceback (most recent call last): + File "<pyshell#82>", line 1, in <module> + a;insert(3,5) +NameError: name 'insert' is not defined +>>> a.insert(3,5) + +>>> a.remove(3) + +>>> a + +[4, 1, 2, 5] +>>> a.pop() + +5 +>>> a + +[4, 1, 2] +>>> a=[1,2,3,4,1,2,1,5] + +>>> a.count(1) + +3 +>>> a.extend([6,7]) + +>>> a + +[1, 2, 3, 4, 1, 2, 1, 5, 6, 7] +>>> a.insert([6,7]) + +Traceback (most recent call last): + File "<pyshell#92>", line 1, in <module> + a.insert([6,7]) +TypeError: insert() takes exactly 2 arguments (1 given) +>>> #리스트의 요소를 제거하는 3가지 방법 remover,pop,del + +>>> a=[1,2,3,'a','b','c'] + +>>> a.remove('a') + +>>> a + +[1, 2, 3, 'b', 'c'] +>>> a.pop(2) + +3 +>>> a + +[1, 2, 'b', 'c'] +>>> del a[2] + +>>> a + +[1, 2, 'c'] +>>> #연습문제 + +>>> # a에서 you too뽑아내기 + +>>> a=['life','is','too','short','you','need','python'] + +>>> a + +['life', 'is', 'too', 'short', 'you', 'need', 'python'] +>>> b= a.pop(4) + +>>> c= a. pop(2) + +>>> b+c + +'youtoo' +>>> type(b) + +<class 'str'> +>>> type(c) + +<class 'str'> +>>> #리스트를 문자열로 만들어 출력하기 + +>>> a=['LIFE','IS','TOO','SHORT'] + +>>> str(a[:]) + +"['LIFE', 'IS', 'TOO', 'SHORT']" +>>> b=str(a[:]) + +>>> type(b) + +<class 'str'> +>>> #리스트의 사이즈 구하기 + +>>> a=[1,2,3] + +>>> b=a.len() + +Traceback (most recent call last): + File "<pyshell#117>", line 1, in <module> + b=a.len() +AttributeError: 'list' object has no attribute 'len' +>>> b=a.len + +Traceback (most recent call last): + File "<pyshell#118>", line 1, in <module> + b=a.len +AttributeError: 'list' object has no attribute 'len' +>>> len(a) + +3 +>>> #리스트에 [4,5]를 append 했을떄와 extend했을때의 차이점 + +>>> a=[1,2,3] + +>>> a.aapend(4,5) + +Traceback (most recent call last): + File "<pyshell#122>", line 1, in <module> + a.aapend(4,5) +AttributeError: 'list' object has no attribute 'aapend' +>>> a.append(4,5) + +Traceback (most recent call last): + File "<pyshell#123>", line 1, in <module> + a.append(4,5) +TypeError: append() takes exactly one argument (2 given) +>>> a.append([4,5]) + +>>> a + +[1, 2, 3, [4, 5]] +>>> a.extend([4,5]) + +>>> a + +[1, 2, 3, [4, 5], 4, 5] +>>> #리스트로 들어가느냐 정수로 들어가느냐 + +>>> #리스트 오름차순으로 + +>>> a=[1,3,5,4,2] + +>>> a.sort() + +>>> a + +[1, 2, 3, 4, 5] +>>> a.reverse() + +>>> a + +[5, 4, 3, 2, 1] +>>> #리스트 삭제 + +>>> a=[1,2,3,4,5] + +>>> a.remove(2,4) + +Traceback (most recent call last): + File "<pyshell#137>", line 1, in <module> + a.remove(2,4) +TypeError: remove() takes exactly one argument (2 given) +>>> a.remove(2) + +>>> a.remove(4) + +>>> a + +[1, 3, 5] +>>>