Skip to content

Commit 647d77d

Browse files
nainsysgitbook-bot
authored andcommitted
GitBook: [master] 6 pages modified
1 parent 53f1305 commit 647d77d

File tree

6 files changed

+194
-3
lines changed

6 files changed

+194
-3
lines changed

3./3.10.-sequence.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

3./3.10.-sequence/3.10.1.-lists.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# 3.10.1. 리스트\(Lists\)
2+
3+
리스트는 대괄호 사이에 쉼표로 구분된 값\(item\)들의 목록으로 작성될 수 있는 파이썬에서 가장 다재 다능한 데이터 유형입니다. 리스트는 목록이라는 뜻으로, 다양한 데이터를 담을 수 있고 내용을 변경할 수 있는 시퀀스입니다. 리스트의 중요한 점은 리스트의 항목이 동일한 유형 일 필요는 없다는 것입니다. 리스트의 인덱스는 0부터 시작합니다.
4+
5+
리스트를 만들 때는 위에서 보는 것과 같이 대괄호\(\[ \]\)로 감싸 주고 각 항목 값들은 쉼표\(,\)로 구분해 줍니다.
6+
7+
```python
8+
list1 = ['physics', 'chemistry', 1997, 2000];
9+
list2 = [1, 2, 3, 4, 5 ];
10+
list3 = ["a", "b", "c", "d"]
11+
list4 = [1, 2, 'Life', 'is']
12+
list5 = [1, 2, ['Life', 'is']]
13+
```
14+
15+
리스트의 각 요소들을 액세스하려면 대괄호를 사용하여 색인과 함께 슬라이싱하고 해당 색인에 있는 값을 구하면 됩니다. \(\* 슬라이싱: 범위를 정해 선택하기\)
16+
17+
```python
18+
list1 = ['physics', 'chemistry', 1997, 2000];
19+
list2 = [1, 2, 3, 4, 5, 6, 7 ];
20+
print "list1[0]: ", list1[0]
21+
print "list2[1:5]: ", list2[1:5]
22+
```
23+
24+
대입 연산자 = 의 왼쪽에 리스트\[인덱스\] 를 제공하여 목록의 단일 또는 여러 요소를 업데이트 할 수 있으며 append\(\) 메서드를 사용하여 목록의 요소에 추가할 수 있습니다. 예를 들어 -
25+
26+
```python
27+
list = ['physics', 'chemistry', 1997, 2000];
28+
print "Value available at index 2 : "
29+
print list[2]
30+
list[2] = 2001;
31+
print "New value available at index 2 : "
32+
print list[2]
33+
```
34+
35+
목록 요소를 제거하려면 삭제할 요소를 정확히 알고 있는 경우 del 문을 사용하고, 모르는 경우 remove\(\) 메서드를 사용할 수 있습니다. 예를 들어 -
36+
37+
```python
38+
list1 = ['physics', 'chemistry', 1997, 2000];
39+
print list1
40+
del list1[2];
41+
print "After deleting value at index 2 : "
42+
print list1
43+
```
44+
45+
리스트는 문자열과 매우 비슷하게 +와 \* 연산자를 사용합니다. 연산의 결과가 새로운 목록이지 문자열이 아니라는 것을 제외하고 + 연산자는 연결, \* 연산자는 반복을 의미합니다.
46+
47+
| **Python Expression** | **Results** | **Description** |
48+
| :--- | :--- | :--- |
49+
| len\(\[1, 2, 3\]\) | 3 | Length |
50+
| \[1, 2, 3\] + \[4, 5, 6\] | \[1, 2, 3, 4, 5, 6\] | Concatenation |
51+
| \['Hi!'\] \* 4 | \['Hi!', 'Hi!', 'Hi!', 'Hi!'\] | Repetition |
52+
| 3 in \[1, 2, 3\] | True | Membership |
53+
| for x in \[1, 2, 3\]: print x, | 1 2 3 | Iteration |
54+
55+
리스트는 시퀀스이므로 문자열과 동일한 방식으로 인덱싱과 슬라이싱 동작을 합니다. 파이썬에는 다음과 같은 리스트 함수와 메서드들이 있습니다.
56+
57+
| [**cmp\(list1, list2\)**](https://www.tutorialspoint.com/python/list_cmp.htm) 두 리스트의 요소를 비교합니다. |
58+
| :--- |
59+
| [**len\(list\)**](https://www.tutorialspoint.com/python/list_len.htm) 리스트의 전체 길이 |
60+
| [**max\(list\)**](https://www.tutorialspoint.com/python/list_max.htm) 리스트에서 최대 값을 가진 항목을 반환 |
61+
| [**min\(list\)**](https://www.tutorialspoint.com/python/list_min.htm) 리스트에서 최대 값을 가진 항목을 반환 |
62+
| [**list\(seq\)**](https://www.tutorialspoint.com/python/list_list.htm) 튜플을 리스트로으로 변환 |
63+
| [**list.append\(obj\)**](https://www.tutorialspoint.com/python/list_append.htm) obj 오브젝트를리스트에 추가 |
64+
| [**list.count\(obj\)**](https://www.tutorialspoint.com/python/list_count.htm) 리스트에 obj가 발생한 횟수를 반환 |
65+
| [**list.extend\(seq\)**](https://www.tutorialspoint.com/python/list_extend.htm) 리스트에 seq의 내용을 추가 |
66+
| [**list.index\(obj\)**](https://www.tutorialspoint.com/python/list_index.htm) obj가 나타나는 리스트 내의 가장 작은 인덱스를 리턴 |
67+
| [**list.insert\(index, obj\)**](https://www.tutorialspoint.com/python/list_insert.htm) 리스트에 객체 obj를 오프셋 index 위치에 삽입 |
68+
| [**list.pop\(obj=list\[-1\]\)**](https://www.tutorialspoint.com/python/list_pop.htm) 리스트에서 마지막 객체 또는 obj를 제거하여 반환. |
69+
| [**list.remove\(obj\)**](https://www.tutorialspoint.com/python/list_remove.htm) 오브젝트 obj를 리스트로부터 삭제 |
70+
| [**list.reverse\(\)**](https://www.tutorialspoint.com/python/list_reverse.htm) 리스트의 대상을 반전 |
71+
| [**list.sort\(\[func\]\)**](https://www.tutorialspoint.com/python/list_sort.htm) 리스트의 객체를 정렬하고, 주어진 compare \[func\]를 사용합니다. |
72+

3./3.10.-sequence/3.10.2.-tuple.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 3.10.2. 튜플\(Tuple\)
2+
3+
튜플은 리스트와 마찬가지로 시퀀스입니다. 튜플과 리스트의 차이점은 리스트와 다르게 튜플은 변경할 수 없고 튜플은 괄호를 사용하는 반면 목록에서는 대괄호를 사용한다는 점입니다. 튜플은 구성요소를 변경할 수 없는 불변 데이터입니다. 연락처 목록처럼 수시로 데이터를 변경해야 하는 데이터는 튜플이 아니라 리스트로 작성해야 합니다. 튜플은 데이터를 나열하되 그 순서나 내용이 변하지 않을 때 잘 적용됩니다.
4+
5+
```python
6+
tup1 = ('physics', 'chemistry', 1997, 2000)
7+
tup2 = (1, 2, 3, 4, 5)
8+
tup3 = "a", "b", "c", "d"
9+
```
10+
11+
튜플의 값에 액세스하려면 대괄호를 사용하여 인덱스와 함께 슬라이스하여 해당 인덱스에서 사용할 수 있는 값을 얻으면 됩니다.
12+
13+
```python
14+
tup1 = ('physics', 'chemistry', 1997, 2000)
15+
tup2 = (1, 2, 3, 4, 5, 6, 7 )
16+
print "tup1[0]: ", tup1[0]
17+
print "tup2[1:5]: ", tup2[1:5]
18+
```
19+
20+
튜플은 변경 불가능합니다. 즉, 튜플 요소의 값을 업데이트하거나 변경할 수 없습니다. 다음 예제와 같이 기존 튜플의 일부를 가져와서 새 튜플을 만들 수는 있습니다.
21+
22+
```python
23+
tup1 = (12, 34.56)
24+
tup2 = ('abc', 'xyz')
25+
tup3 = tup1 + tup2
26+
print tup3
27+
```
28+
29+
튜플은 문자열과 매우 비슷하게 + 및 \* 연산자를 사용할 수 있습니다.
30+
31+
| Python Expression | Results | Description |
32+
| :--- | :--- | :--- |
33+
| len\(\(1, 2, 3\)\) | 3 | Length |
34+
| \(1, 2, 3\) + \(4, 5, 6\) | \(1, 2, 3, 4, 5, 6\) | Concatenation |
35+
| \('Hi!',\) \* 4 | \('Hi!', 'Hi!', 'Hi!', 'Hi!'\) | Repetition |
36+
| 3 in \(1, 2, 3\) | True | Membership |
37+
| for x in \(1, 2, 3\): print x, | 1 2 3 | Iteration |
38+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# 3.10.3. 딕셔너리\(Dictionary\)
2+
3+
딕셔너리는 변하지 않는 고유한 키\(key\)와 변하는 값\(value\)으로 맵핑되어 있는 순서가 없는 집합입니다. 각 키는 값 콜론 \(:\)으로 구분되고 항목은 쉼표로 구분되며 전체는 중괄호로 묶입니다. 딕셔너리 요소에 액세스하려면 대괄호를 키와 함께 사용하여 값을 가져올 수 있습니다.
4+
5+
```python
6+
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
7+
print "dict['Name']: ", dict['Name']
8+
print "dict['Age']: ", dict['Age']
9+
```
10+
11+
아래 예제와 같이 새 항목 또는 키:값 쌍을 추가하거나 기존 항목을 수정하거나 기존 항목을 삭제하여 딕셔너리를 업데이트 할 수 있습니다.
12+
13+
```python
14+
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
15+
dict['Age'] = 8; # update existing entry
16+
dict['School'] = "DPS School"; # Add new entry
17+
print "dict['Age']: ", dict['Age']
18+
print "dict['School']: ", dict['School']
19+
```
20+
21+
개별 딕셔너리 요소를 제거하거나 딕셔너리의 전체 내용을 지울 수 있습니다. del 문을 사용하여 한 번에 전체 딕셔너리를 삭제할 수도 있습니다.
22+
23+
```python
24+
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
25+
del dict['Name']; # remove entry with key 'Name'
26+
dict.clear(); # remove all entries in dict
27+
del dict ; # delete entire dictionary
28+
print "dict['Age']: ", dict['Age']
29+
print "dict['School']: ", dict['School']
30+
```
31+
32+
위의 코드를 실행하면 del dict문 실행으로 딕셔너리가 더 이상 존재하지 않기 때문에 예외 에러가 발생합니다.
33+
34+
```python
35+
dict['Age']:
36+
Traceback (most recent call last):
37+
File "test.py", line 8, in <module>
38+
print "dict['Age']: ", dict['Age'];
39+
TypeError: 'type' object is unsubscriptable
40+
```
41+
42+
딕셔너리 키에 대해 기억해야 할 두 가지 중요한 사항이 있습니다.
43+
44+
- 중복 키가 허용되지 않는다. 할당 중 중복 키가 발견되면 마지막으로 할당된 값이 사용됩니다.
45+
46+
```python
47+
dict = {'Name': 'Zara', 'Age': 7, 'Name': 'Manni'}
48+
print "dict['Name']: ", dict['Name']
49+
```
50+
51+
- 키는 불변이어야 합니다. 즉, 문자열, 숫자 또는 튜플을 사전 키로 사용할 수 있지만 \['key'\]와 같은 것은 허용되지 않는다.
52+
53+
다음과 같은 딕셔너리 함수와 메서드들이 있습니다.
54+
55+
| [cmp\(dict1, dict2\)](https://www.tutorialspoint.com/python/dictionary_cmp.htm) | 두 dictionary의 요소를 비교합니다. |
56+
| :--- | :--- |
57+
| [len\(dict\)](https://www.tutorialspoint.com/python/dictionary_len.htm) | Dictionary의 전체 길이를 제공합니다. 이것은 dictionary에 있는 항목의 수와 같습니다. |
58+
| [str\(dict\)](https://www.tutorialspoint.com/python/dictionary_str.htm) | dictionary의 인쇄 가능한 문자열 표현을 생성합니다. |
59+
| [type\(variable\)](https://www.tutorialspoint.com/python/dictionary_type.htm) | 전달된 변수의 유형을 반환합니다. |
60+
| [dict.clear\(\)](https://www.tutorialspoint.com/python/dictionary_clear.htm) | dictionary dict의 모든 요소를 제거합니다. |
61+
| [dict.copy\(\)](https://www.tutorialspoint.com/python/dictionary_copy.htm) | dictionary dict의 얕은 복사본을 반환합니다. |
62+
| [dict.fromkeys\(\)](https://www.tutorialspoint.com/python/dictionary_fromkeys.htm) | seq의 키와 값을 value로 설정하여 새 dictionary를 만듭니다. |
63+
| [dict.get\(key, default=None\)](https://www.tutorialspoint.com/python/dictionary_get.htm) | 키에 해당 하는 값을 리턴, 키가 dictionary에 없는 경우 default를 리턴 |
64+
| [dict.has\_key\(key\)](https://www.tutorialspoint.com/python/dictionary_has_key.htm) | dictionary dict에 key가 있으면 true 그렇지 않으면 false를 반환합니다. |
65+
| [dict.items\(\)](https://www.tutorialspoint.com/python/dictionary_items.htm) | dict \(키, 값\) 튜플 쌍의 목록을 반환 |
66+
| [dict.keys\(\)](https://www.tutorialspoint.com/python/dictionary_keys.htm) | dict의 키 리스트를 반환 |
67+
| [dict.setdefault\(key, default=None\)](https://www.tutorialspoint.com/python/dictionary_setdefault.htm) | get \(\)과 유사하지만 키가 dict에 없는 경우 dict \[key\] = default로 설정 |
68+
| [dict.update\(dict2\)](https://www.tutorialspoint.com/python/dictionary_update.htm) | dictionary dict2의 키 - 값 쌍을 dict에 추가 |
69+
| [dict.values\(\)](https://www.tutorialspoint.com/python/dictionary_values.htm) | dictionary dict의 값 목록을 반환 |
70+

3./3.10.-sequence/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# 3.10. 시퀀스\(Sequence\) 자료형 활용
2+
3+
파이썬에서 가장 기본적인 데이터 구조는 시퀀스입니다. 시퀀스란 데이터를 순서대로 하나씩 나열하여 나타낸 데이터 구조입니다.
4+
5+
시퀀스의 각 요소에는 특정 위치\(~번째\)의 데이터를 가리키는 인덱스가 지정됩니다. 첫 번째 인덱스는 0이고, 두 번째 인덱스는 1입니다.
6+
7+
파이썬에는 여섯 가지 시퀀스 유형이 있지만 가장 일반적인 것은 list과 tuple입니다.
8+
9+
색인 생성, 분리, 추가, 곱하기 및 구성원 확인 등이 시퀀스 유형으로 처리되는 일들입니다.
10+

SUMMARY.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@
8383
* [3.9.3. 문자열 연산자](3./3.9.-strings/3.9.3..md)
8484
* [3.9.4. 문자열 포맷 연산자](3./3.9.-strings/3.9.4..md)
8585
* [3.9.5. 내장 문자열 함수](3./3.9.-strings/3.9.5..md)
86-
* [3.10. 시퀀스\(Sequence\) 자료형 활용](3./3.10.-sequence.md)
86+
* [3.10. 시퀀스\(Sequence\) 자료형 활용](3./3.10.-sequence/README.md)
87+
* [3.10.1. 리스트\(Lists\)](3./3.10.-sequence/3.10.1.-lists.md)
88+
* [3.10.2. 튜플\(Tuple\)](3./3.10.-sequence/3.10.2.-tuple.md)
89+
* [3.10.3. 딕셔너리\(Dictionary\)](3./3.10.-sequence/3.10.3.-dictionary.md)
8790
* [3.11. Date & Time](3./3.11.-date-and-time.md)
8891
* [3.12. 파이썬 에러처리](3./3.12..md)
8992
* [4. NumPy & SciPy](4.-numpy-and-scipy.md)

0 commit comments

Comments
 (0)