다른 명령
(같은 사용자의 중간 판 2개는 보이지 않습니다) | |||
4번째 줄: | 4번째 줄: | ||
! 구분 !! List !! Dictionary !! Tuple | ! 구분 !! List !! Dictionary !! Tuple | ||
|- | |- | ||
! | ! 정의 | ||
| Ordered, mutable sequence of items | | Ordered, mutable sequence of items | ||
|Unordered, mutable collection of key-value pairs | |Unordered, mutable collection of key-value pairs | ||
| Ordered, immutable sequence of items | | Ordered, immutable sequence of items | ||
|- | |- | ||
! | ! 사용 문법 | ||
| `[1, 2, 3]` | | `[1, 2, 3]` | ||
| `{'key1': 'value1', 'key2': 'value2'}` | | `{'key1': 'value1', 'key2': 'value2'}` | ||
| `(1, 2, 3)` | | `(1, 2, 3)` | ||
|- | |- | ||
! | ! Mutable? | ||
| Yes | Yes | No | | Yes | ||
| Yes | |||
| No | |||
|- | |- | ||
! | ! Indexed Access | ||
| Yes (by index) | Yes (by key) | Yes (by index) | | Yes (by index) | ||
| Yes (by key) | |||
| Yes (by index) | |||
|- | |- | ||
! | ! 증복허용 여부 | ||
| Yes | No (keys must be unique) | Yes | | Yes | ||
| No (keys must be unique) | |||
| Yes | |||
|- | |- | ||
! | ! 사용예시 | ||
| Storing collections of items where order matters | | Storing collections of items where order matters | ||
| Storing key-value pairs for fast lookup | | Storing key-value pairs for fast lookup | ||
| Storing fixed collections that should not change | | Storing fixed collections that should not change | ||
|- | |- | ||
! | ! 언제 사용 하나? | ||
| When you need an ordered and mutable sequence | | When you need an ordered and mutable sequence | ||
| When you need to associate values with unique keys | | When you need to associate values with unique keys | ||
| When you need an ordered and immutable collection | | When you need an ordered and immutable collection | ||
|- | |- | ||
! | ! Example | ||
| <source lang="python"> | | <source lang="python"> | ||
my_list = [1, 2, 3] | my_list = [1, 2, 3] | ||
47번째 줄: | 53번째 줄: | ||
</source> | </source> | ||
|} | |} | ||
[[category:python]] |
2025년 6월 28일 (토) 15:54 기준 최신판
튜플 딕셔너리 리스트 차이점 ,특징
구분 | List | Dictionary | Tuple |
---|---|---|---|
정의 | Ordered, mutable sequence of items | Unordered, mutable collection of key-value pairs | Ordered, immutable sequence of items |
사용 문법 | `[1, 2, 3]` | `{'key1': 'value1', 'key2': 'value2'}` | `(1, 2, 3)` |
Mutable? | Yes | Yes | No |
Indexed Access | Yes (by index) | Yes (by key) | Yes (by index) |
증복허용 여부 | Yes | No (keys must be unique) | Yes |
사용예시 | Storing collections of items where order matters | Storing key-value pairs for fast lookup | Storing fixed collections that should not change |
언제 사용 하나? | When you need an ordered and mutable sequence | When you need to associate values with unique keys | When you need an ordered and immutable collection |
Example | my_list = [1, 2, 3] print(my_list[0]) # Output: 1 |
my_dict = {'name': 'Alice', 'age': 25} print(my_dict['name']) # Output: Alice |
my_tuple = (1, 2, 3) print(my_tuple[1]) # Output: 2 |