메뉴 여닫기
개인 메뉴 토글
로그인하지 않음
만약 지금 편집한다면 당신의 IP 주소가 공개될 수 있습니다.

튜플 리스트 딕셔너리 차이점,특징,사용예시: 두 판 사이의 차이

데브카페
편집 요약 없음
 
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?**
! Mutable?
| Yes  
| Yes  
| Yes  
| Yes  
| No
| No
|-
|-
! **Indexed Access**
! Indexed Access
| Yes (by index)  
| Yes (by index)  
| Yes (by key)  
| Yes (by key)  
| Yes (by index)
| Yes (by index)
|-
|-
! **증복허용 여부 **
! 증복허용 여부  
| Yes  
| Yes  
| No (keys must be unique)  
| No (keys must be unique)  
| Yes
| 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 Code**
! Example
| <source lang="python">
| <source lang="python">
my_list = [1, 2, 3]
my_list = [1, 2, 3]

2025년 6월 28일 (토) 15:54 기준 최신판

튜플 딕셔너리 리스트 차이점 ,특징

List, Dictionary, Tuple 비교
구분 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

Comments