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

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

데브카페
2번째 줄: 2번째 줄:
{| class="wikitable"
{| class="wikitable"
|+ List, Dictionary, Tuple 비교
|+ List, Dictionary, Tuple 비교
! Feature !! List !! Dictionary !! Tuple
! 구분 !! List !! Dictionary !! Tuple
|-
|-
! **정의**
! **정의**
| Ordered, mutable sequence of items|Unordered, mutable collection of key-value pairs | Ordered, immutable sequence of items
| 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)`
| `[1, 2, 3]`  
| `{'key1': 'value1', 'key2': 'value2'}`  
| `(1, 2, 3)`
|-
|-
! **Mutable?**
! **Mutable?**
20번째 줄: 24번째 줄:
|-
|-
! ** 사용예시 **
! ** 사용예시 **
| Storing collections of items where order matters | Storing key-value pairs for fast lookup | Storing fixed collections that should not change
| 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
| 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 Code**
! **Example Code**
| <syntaxhighlight lang="python">
| <source lang="python">
my_list = [1, 2, 3]
my_list = [1, 2, 3]
print(my_list[0])  # Output: 1
print(my_list[0])  # Output: 1
</syntaxhighlight>
</source>
| <syntaxhighlight lang="python">
|<source lang=python>
my_dict = {'name': 'Alice', 'age': 25}
my_dict = {'name': 'Alice', 'age': 25}
print(my_dict['name'])  # Output: Alice
print(my_dict['name'])  # Output: Alice
</syntaxhighlight>
</source>
| <syntaxhighlight lang="python">
|<source lang=python>
my_tuple = (1, 2, 3)
my_tuple = (1, 2, 3)
print(my_tuple[1])  # Output: 2
print(my_tuple[1])  # Output: 2
</syntaxhighlight>
</source>
|}
|}

2024년 10월 21일 (월) 20:42 판

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

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 | No
**Indexed Access** Yes (by key) | Yes (by index)
**증복허용 여부 ** 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 Code**
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